| 1 | # ABSTRACT: List the contents of a stack | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Pinto::Action::List; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use MooseX::Types::Moose qw(Str Bool); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Pinto::Constants qw(:color); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Pinto::Types qw(StackName StackDefault StackObject); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 6 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 6 | extends qw( Pinto::Action ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | has stack => ( | |||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||
| 25 | isa => StackName | StackDefault | StackObject, | ||||||||||||||||||||||||||||
| 26 | default => undef, | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | has pinned => ( | |||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||
| 31 | isa => Bool, | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 6 | has authors => ( | |||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||
| 36 | isa => Str, | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 6 | has packages => ( | |||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | isa => Str, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 6 | has distributions => ( | |||||||||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||||||||||
| 46 | isa => Str, | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | has all => ( | |||||||||||||||||||||||||||
| 50 | is => 'ro', | ||||||||||||||||||||||||||||
| 51 | isa => Bool, | ||||||||||||||||||||||||||||
| 52 | default => 0, | ||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 6 | has format => ( | |||||||||||||||||||||||||||
| 56 | is => 'ro', | ||||||||||||||||||||||||||||
| 57 | isa => Str, | ||||||||||||||||||||||||||||
| 58 | default => '[%F] %-40p %12v %a/%f', | ||||||||||||||||||||||||||||
| 59 | lazy => 1, | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 9 | ▶ | sub _where { | ||||||||||||||||||||||||||
|
Subroutine
_where: called CC=9 SCAR=27.0
| |||||||||||||||||||||||||||||
| 65 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 9 | my $where = {}; | |||||||||||||||||||||||||||
| 68 | 9 | ▶ | if ($self->all) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ( my $pkg_name = $self->packages ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $where->{'me.name'} = {regexp => qr/$pkg_name/ }; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( my $dist_name = $self->distributions ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | $where->{'distribution.archive'} = {regexp => qr/$dist_name/}; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ( my $authors = $self->authors ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | $where->{'distribution.author'} = {regexp => qr/$authors/i}; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 9 | my $stack = $self->repo->get_stack( $self->stack ); | |||||||||||||||||||||||||||
| 85 | 9 | $where = {revision => $stack->head->id}; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 9 | ▶ | if ( my $pkg_name = $self->packages ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 1 | $where->{'package.name'} = {regexp => qr/$pkg_name/}; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 9 | ▶ | if ( my $dist_name = $self->distributions ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 1 | $where->{'distribution.archive'} = {regexp => qr/$dist_name/}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 9 | ▶ | if ( my $authors = $self->authors ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 2 | $where->{'distribution.author'} = {regexp => qr/$authors/i}; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 9 | ▶ | if ( my $pinned = $self->pinned ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | $where->{is_pinned} = 1; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 9 | return $where; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 9 | ▶ | sub _attrs { | ||||||||||||||||||||||||||
|
Subroutine
_attrs: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 110 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 9 | my $attrs = {}; | |||||||||||||||||||||||||||
| 113 | 9 | ▶ | if ($self->all) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | $attrs = { prefetch => [qw(distribution)], order_by => ['me.name'] }; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||
| 117 | 9 | $attrs = { prefetch => [qw(package distribution)] }; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 9 | return $attrs; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 9 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=8 SCAR=28.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 9 | my $where = $self->_where; | |||||||||||||||||||||||||||
| 130 | 9 | my $attrs = $self->_attrs; | |||||||||||||||||||||||||||
| 131 | 9 | ▶ | my $method = 'search_' . ($self->all ? 'package' : 'registration'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 9 | my $rs = $self->repo->db->schema->$method( $where, $attrs ); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 9 | my $did_match = 0; | |||||||||||||||||||||||||||
| 135 | 9 | ▶ | while ( my $it = $rs->next ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # $it could be a registration or a package object, depending | ||||||||||||||||||||||||||||
| 138 | # on whether we are listing a stack or the whole repository | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | my $string = $it->to_string( $self->format ); | |||||||||||||||||||||||||||
| 141 | 0 | my $color = undef; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $color = $PINTO_PALETTE_COLOR_0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | if $it->distribution->is_local; | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $color = $PINTO_PALETTE_COLOR_1 | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$it->isa("Pinto::Schema::Result::Registration") and $it->is_pinned
MC/DC0%0/2
$it->isa("Pinto::Schema::Result::Registration") and $it->is_pinned
$it->isa("Pinto::Schema::Result::Registration")
$it->is_pinned
Truth table0%0/3
A and B
A= $it->isa("Pinto::Schema::Result::Registration")B= $it->is_pinned
| |||||||||||||||||||||||||||||
| 147 | if $it->isa('Pinto::Schema::Result::Registration') && $it->is_pinned; | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | $self->show( $string, { color => $color } ); | |||||||||||||||||||||||||||
| 150 | 0 | $did_match++; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # If there are any search criteria and nothing matched, | ||||||||||||||||||||||||||||
| 154 | # then the exit status should not be successful. | ||||||||||||||||||||||||||||
| 155 | 9 | ▶ | $self->result->failed if keys %$where > 1 && !$did_match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
keys %$where > 1 and not $did_match
MC/DC50%1/2
keys %$where > 1 and not $did_match
keys %$where > 1
not $did_match
Truth table66%2/3
A and not(B)
A= keys %$where > 1B= not $did_match
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 9 | return $self->result; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 6 | 1; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | __END__ | ||||||||||||||||||||||||||||