blib/lib/Pinto/Action/List.pm

filter: Statementstmt 80.0% 56 / 70 Branchbran 46.4% 13 / 28 Conditioncond 33.3% 2 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 1 totaltotal 68.6% 81 / 118 CC 17 SCAR 24.1
CC
17
Cov
68%
execute
16.8
_where
14.9
_attrs
2.1
CRAP 11.1
« blib/lib/App/Pinto/Command.pm ↑ Summary blib/lib/Pinto/Action/Verify.pm »
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
BranchTrueFalseTotal
if ($self->all) { } 0 9 9
69  
70 0 ▶ if ( my $pkg_name = $self->packages ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg_name = $self->packages) 0 0 0
71 0 $where->{'me.name'} = {regexp => qr/$pkg_name/ };
72 }
73  
74 0 ▶ if ( my $dist_name = $self->distributions ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dist_name = $self->distributions) 0 0 0
75 0 $where->{'distribution.archive'} = {regexp => qr/$dist_name/};
76 }
77  
78 0 ▶ if ( my $authors = $self->authors ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $authors = $self->authors) 0 0 0
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
BranchTrueFalseTotal
if (my $pkg_name = $self->packages) 1 8 9
88 1 $where->{'package.name'} = {regexp => qr/$pkg_name/};
89 }
90  
91 9 ▶ if ( my $dist_name = $self->distributions ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dist_name = $self->distributions) 1 8 9
92 1 $where->{'distribution.archive'} = {regexp => qr/$dist_name/};
93 }
94  
95 9 ▶ if ( my $authors = $self->authors ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $authors = $self->authors) 2 7 9
96 2 $where->{'distribution.author'} = {regexp => qr/$authors/i};
97 }
98  
99 9 ▶ if ( my $pinned = $self->pinned ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pinned = $self->pinned) 0 9 9
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
BranchTrueFalseTotal
if ($self->all) { } 0 9 9
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
BranchTrueFalseTotal
$self->all ? : 0 9 9
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
BranchTrueFalseTotal
if (my $it = $rs->next) 0 9 9
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
BranchTrueFalseTotal
if $it->distribution->is_local 0 0 0
144 if $it->distribution->is_local;
145  
146 0 ▶ $color = $PINTO_PALETTE_COLOR_1
Branch: 1 branch
BranchTrueFalseTotal
if $it->isa("Pinto::Schema::Result::Registration") and $it->is_pinned 0 0 0
Condition0%0/3
$it->isa("Pinto::Schema::Result::Registration") and $it->is_pinned
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if keys %$where > 1 and not $did_match 4 5 9
Condition66%2/3
keys %$where > 1 and not $did_match
!ll&&!rl&&r
504
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
ABresult
0X0
100
111
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__
« blib/lib/App/Pinto/Command.pm ↑ Summary blib/lib/Pinto/Action/Verify.pm »