blib/lib/Pinto/Role/Puller.pm

filter: Statementstmt 85.5% 77 / 90 Branchbran 63.8% 23 / 36 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 4 totaltotal 77.3% 116 / 150 CC 21 SCAR 15.8
CC
21
Cov
78%
find
9.5
__ANON__
7.1
pull
6.6
CRAP 4.9
« blib/lib/App/Pinto/Command/install.pm ↑ Summary blib/lib/Pinto/Remote.pm »
1 # ABSTRACT: Something pulls packages to a stack
2  
3 package Pinto::Role::Puller;
4  
5 43 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 43 ▶use MooseX::Types::Moose qw(ArrayRef Bool Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 43 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 43 ▶use List::MoreUtils qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 43 ▶use Pinto::Util qw(throw whine);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 #-----------------------------------------------------------------------------
14  
15 43 our $VERSION = '0.14'; # VERSION
16  
17 #-----------------------------------------------------------------------------
18  
19 43 with qw( Pinto::Role::Plated );
20  
21 #-----------------------------------------------------------------------------
22  
23 has recurse => (
24 is => 'ro',
25 isa => Bool,
26 32 ▶ default => sub { shift->stack->repo->config->recurse },
Subroutine __ANON__: called CC=1 SCAR=0.0
27 43 lazy => 1,
28 );
29  
30 43 has cascade => (
31 is => 'ro',
32 isa => Bool,
33 default => 0,
34 );
35  
36 43 has pin => (
37 is => 'ro',
38 isa => Bool,
39 default => 0,
40 );
41  
42 43 has force => (
43 is => 'ro',
44 isa => Bool,
45 default => 0,
46 );
47  
48 has skip_missing_prerequisite => (
49 is => 'ro',
50 isa => ArrayRef[Str],
51 64 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 43 );
53  
54 43 has skip_all_missing_prerequisites => (
55 is => 'ro',
56 isa => Bool,
57 default => 0,
58 );
59  
60 43 has with_development_prerequisites => (
61 is => 'ro',
62 isa => Bool,
63 default => 0,
64 );
65  
66 #-----------------------------------------------------------------------------
67  
68 # We should require a stack() attribute here, but Moose can't properly
69 # resolve attributes that are composed from other roles. For more info
70 # see https://rt.cpan.org/Public/Bug/Display.html?id=46347
71  
72 # requires qw(stack);
73  
74 #-----------------------------------------------------------------------------
75  
76 62 ▶sub pull {
Subroutine pull: called CC=6 SCAR=18.8
Pod undocumented
77 62 my ( $self, %args ) = @_;
78  
79 62 my $target = $args{target};
80 62 my $stack = $self->stack;
81  
82 62 my $did_register = 0;
83 62 my $did_register_prereqs = 0;
84 62 my $dist;
85  
86 62 ▶ if ( $target->isa('Pinto::Schema::Result::Distribution') ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($target->isa('Pinto::Schema::Result::Distribution')) { } 59 3 62
elsif ($target->isa('Pinto::Target::Distribution')) { } 0 3 3
elsif ($target->isa('Pinto::Target::Package')) { } 3 0 3
87 59 $dist = $target;
88 }
89 elsif ( $target->isa('Pinto::Target::Distribution') ) {
90 0 $dist = $self->find( target => $target );
91 }
92 elsif ( $target->isa('Pinto::Target::Package') ) {
93  
94 3 my $tpv = $stack->target_perl_version;
95 3 ▶ if ( $target->is_core( in => $tpv ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target->is_core("in", $tpv)) 0 3 3
96 0 $self->warning("Skipping $target: included in perl $tpv core");
97 0 return (undef, 0, 0); # Nothing was pulled
98 }
99  
100 3 $dist = $self->find( target => $target );
101 }
102 else {
103 0 throw "Illeagal arguments";
104 }
105  
106 60 $did_register = $dist->register( stack => $stack, pin => $self->pin, force => $self->force );
107 59 ▶ $did_register_prereqs = $self->do_recursion( start => $dist ) if $self->recurse;
Branch: 1 branch
BranchTrueFalseTotal
if $self->recurse 32 27 59
108  
109 59 return ($dist, $did_register, $did_register_prereqs);
110 }
111  
112 #-----------------------------------------------------------------------------
113  
114 5 ▶sub find {
Subroutine find: called CC=6 SCAR=22.5
Pod undocumented
115 5 my ( $self, %args ) = @_;
116  
117 5 my $target = $args{target};
118 5 my $stack = $self->stack;
119  
120 5 my $dist;
121 my $msg;
122  
123 5 ▶ if ( $dist = $stack->get_distribution( target => $target ) ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($dist = $stack->get_distribution('target', $target)) { } 0 5 5
elsif ($dist = $stack->repo->get_distribution('target', $target)) { } 0 5 5
elsif ($dist = $stack->repo->ups_distribution('target', $target, 'cascade', $self->cascade)) { } 0 5 5
elsif ($self->should_skip_missing_prerequisite($target)) { } 3 2 5
124 0 $msg = "Found $target on stack $stack in $dist";
125 }
126 elsif ( $dist = $stack->repo->get_distribution( target => $target ) ) {
127 0 $msg = "Found $target in $dist";
128 }
129 elsif ( $dist = $stack->repo->ups_distribution( target => $target, cascade => $self->cascade ) ) {
130 0 $msg = "Found $target in " . $dist->source;
131 }
132 elsif ( $self->should_skip_missing_prerequisite($target) ) {
133 3 whine "Cannot find $target anywhere. Skipping it";
134 3 return;
135 }
136 else {
137 2 throw "Cannot find $target anywhere";
138 }
139  
140 0 $self->chrome->show_progress;
141 0 ▶ $self->info($msg) if defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $msg 0 0 0
142  
143 0 return $dist;
144 }
145  
146 #-----------------------------------------------------------------------------
147  
148 32 ▶sub do_recursion {
Subroutine do_recursion: called CC=3 SCAR=11.3
Pod undocumented
149 32 my ( $self, %args ) = @_;
150  
151 32 my $dist = $args{start};
152 32 my $stack = $self->stack;
153  
154 32 my %last_seen;
155 32 my $did_register = 0;
156  
157 2 ▶ my $cb = sub {
Subroutine __ANON__: called CC=5 SCAR=19.6
158 2 my ($prereq) = @_;
159  
160 2 my $target = $prereq->as_target;
161 2 my $pkg_name = $target->name;
162 2 my $pkg_vers = $target->version;
163  
164 # version sees undef and 0 as equal, so must also check definedness
165 # when deciding if we've seen this version (or newer) of the package
166 2 ▶ return if defined( $last_seen{$pkg_name} ) && $target->is_satisfied_by( $last_seen{$pkg_name} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $last_seen{$pkg_name} and $target->is_satisfied_by($last_seen{$pkg_name}) 0 2 2
Condition33%1/3
defined $last_seen{$pkg_name} and $target->is_satisfied_by($last_seen{$pkg_name})
!ll&&!rl&&r
200
MC/DC0%0/2
defined $last_seen{$pkg_name} and $target->is_satisfied_by($last_seen{$pkg_name})
defined $last_seen{$pkg_name} $target->is_satisfied_by($last_seen{$pkg_name})
Truth table33%1/3
A and B
A= defined $last_seen{$pkg_name}B= $target->is_satisfied_by($last_seen{$pkg_name})
ABresult
0X0
100
111
167  
168 2 ▶ return if not my $dist = $self->find( target => $target );
Branch: 1 branch
BranchTrueFalseTotal
unless my $dist = $self->find("target", $target) 2 0 2
169  
170 0 $did_register += $dist->register( stack => $stack, force => $self->force);
171  
172 # Record the most recent version of the packages that has
173 # been registered, so we don't need to find it again.
174 0 $last_seen{$_->name} = $_->version for $dist->packages;
175  
176 0 return $dist;
177 32 };
178  
179 # Exclude perl itself, and prereqs that are satisfied by the core
180 32 ▶ my @filters = ( sub { $_[0]->is_perl || $_[0]->is_core( in => $stack->target_perl_version ) } );
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_perl or $_[0]->is_core("in", $stack->target_perl_version) 1 3 4
181  
182 # Exlucde develop-time dependencies, unless asked not to
183 2 ▶ push @filters, sub { $_[0]->phase eq 'develop' }
Subroutine __ANON__: called CC=1 SCAR=0.0
184 32 ▶ unless $self->with_development_prerequisites;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->with_development_prerequisites 32 0 32
185  
186 32 require Pinto::PrerequisiteWalker;
187 32 my $walker = Pinto::PrerequisiteWalker->new( start => $dist, callback => $cb, filters => \@filters );
188  
189 32 $self->notice("Descending into prerequisites for $dist");
190  
191 32 ▶ while ( $walker->next ) { }; # Just want the callback side effects
Branch: 1 branch
BranchTrueFalseTotal
if ($walker->next) 2 32 34
192  
193 32 return $did_register;
194 }
195  
196 #-----------------------------------------------------------------------------
197  
198 5 ▶sub should_skip_missing_prerequisite {
Subroutine should_skip_missing_prerequisite: called CC=4 SCAR=14.0
Pod undocumented
199 5 my ($self, $target) = @_;
200  
201 5 ▶ return 1 if $self->skip_all_missing_prerequisites;
Branch: 1 branch
BranchTrueFalseTotal
if $self->skip_all_missing_prerequisites 3 2 5
202 2 ▶ return 0 unless my @skips = @{ $self->skip_missing_prerequisite };
Branch: 1 branch
BranchTrueFalseTotal
unless my(@skips) = @{$self->skip_missing_prerequisite;} 0 2 2
203 2 ▶ return 1 if any { $target->name eq $_ } @skips;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
if &any(sub { $target->name eq $_; } , @skips) 0 2 2
204 2 return 0;
205 }
206  
207 #-----------------------------------------------------------------------------
208 43 1;
209  
210 __END__
« blib/lib/App/Pinto/Command/install.pm ↑ Summary blib/lib/Pinto/Remote.pm »