our
$VERSION
=
'0.14'
;
has
stack
=> (
is
=>
'ro'
,
isa
=> StackName | StackDefault | StackObject,
default
=>
undef
,
);
has
pinned
=> (
is
=>
'ro'
,
isa
=> Bool,
);
has
authors
=> (
is
=>
'ro'
,
isa
=> Str,
);
has
packages
=> (
is
=>
'ro'
,
isa
=> Str,
);
has
distributions
=> (
is
=>
'ro'
,
isa
=> Str,
);
has
all
=> (
is
=>
'ro'
,
isa
=> Bool,
default
=> 0,
);
has
format
=> (
is
=>
'ro'
,
isa
=> Str,
default
=>
'[%F] %-40p %12v %a/%f'
,
lazy
=> 1,
);
sub
_where {
my
(
$self
) =
@_
;
my
$where
= {};
if
(
$self
->all) {
if
(
my
$pkg_name
=
$self
->packages ) {
$where
->{
'me.name'
} = {
regexp
=>
qr/$pkg_name/
};
}
if
(
my
$dist_name
=
$self
->distributions ) {
$where
->{
'distribution.archive'
} = {
regexp
=>
qr/$dist_name/
};
}
if
(
my
$authors
=
$self
->authors ) {
$where
->{
'distribution.author'
} = {
regexp
=>
qr/$authors/
i};
}
}
else
{
my
$stack
=
$self
->repo->get_stack(
$self
->stack );
$where
= {
revision
=>
$stack
->head->id};
if
(
my
$pkg_name
=
$self
->packages ) {
$where
->{
'package.name'
} = {
regexp
=>
qr/$pkg_name/
};
}
if
(
my
$dist_name
=
$self
->distributions ) {
$where
->{
'distribution.archive'
} = {
regexp
=>
qr/$dist_name/
};
}
if
(
my
$authors
=
$self
->authors ) {
$where
->{
'distribution.author'
} = {
regexp
=>
qr/$authors/
i};
}
if
(
my
$pinned
=
$self
->pinned ) {
$where
->{is_pinned} = 1;
}
}
return
$where
;
}
sub
_attrs {
my
(
$self
) =
@_
;
my
$attrs
= {};
if
(
$self
->all) {
$attrs
= {
prefetch
=> [
qw(distribution)
],
order_by
=> [
'me.name'
] };
}
else
{
$attrs
= {
prefetch
=> [
qw(package distribution)
] };
}
return
$attrs
;
}
sub
execute {
my
(
$self
) =
@_
;
my
$where
=
$self
->_where;
my
$attrs
=
$self
->_attrs;
my
$method
=
'search_'
. (
$self
->all ?
'package'
:
'registration'
);
my
$rs
=
$self
->repo->db->schema->
$method
(
$where
,
$attrs
);
my
$did_match
= 0;
while
(
my
$it
=
$rs
->
next
) {
my
$string
=
$it
->to_string(
$self
->
format
);
my
$color
=
undef
;
$color
=
$PINTO_PALETTE_COLOR_0
if
$it
->distribution->is_local;
$color
=
$PINTO_PALETTE_COLOR_1
if
$it
->isa(
'Pinto::Schema::Result::Registration'
) &&
$it
->is_pinned;
$self
->show(
$string
, {
color
=>
$color
} );
$did_match
++;
}
$self
->result->failed
if
keys
%$where
> 1 && !
$did_match
;
return
$self
->result;
}
__PACKAGE__->meta->make_immutable;
1;