blib/lib/Pinto/Action/Update.pm

filter: Statementstmt 37.5% 33 / 88 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 53.3% 8 / 15 Podpod 0.0% 0 / 2 totaltotal 28.4% 41 / 144 CC 17 SCAR 34.5
CC
17
Cov
27%
update
90.0
compute_targets
20.0
execute
12.0
CRAP 31.4
« blib/lib/Pinto/Schema/Result/Distribution.pm ↑ Summary blib/lib/Pinto/Action/Stacks.pm »
1 # ABSTRACT: Update packages to latest versions
2  
3 package Pinto::Action::Update;
4  
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooseX::Types::Moose qw(Bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Pinto::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Pinto::Types qw(PackageTargetList);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Pinto::Target::Package;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #------------------------------------------------------------------------------
17  
18 1 our $VERSION = '0.14'; # VERSION
19  
20 #------------------------------------------------------------------------------
21  
22 1 extends qw( Pinto::Action );
23  
24 #------------------------------------------------------------------------------
25  
26 has targets => (
27 isa => PackageTargetList,
28 traits => [qw(Array)],
29 handles => { targets => 'elements' },
30 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 1 coerce => 1,
32 );
33  
34 1 has all => (
35 is => 'ro',
36 isa => Bool,
37 default => 0,
38 );
39  
40 1 has roots => (
41 is => 'ro',
42 isa => Bool,
43 default => 0,
44 );
45  
46 1 has no_fail => (
47 is => 'ro',
48 isa => Bool,
49 default => 0,
50 );
51  
52 #------------------------------------------------------------------------------
53  
54 1 with qw( Pinto::Role::Committable Pinto::Role::Puller );
55  
56 #------------------------------------------------------------------------------
57  
58 0 ▶sub execute {
Subroutine execute: not called CC=3 SCAR=24.8
59 0 my ($self) = @_;
60  
61 0 my $stack = $self->stack;
62 0 my @targets = $self->compute_targets;
63  
64 0 for my $target ( @targets ) {
65  
66 0 ▶ if ($target->version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target->version) 0 0 0
67 0 $self->warning("Ignoring version specification on target $target");
68 0 $target = $target->unversioned;
69 }
70  
71 0 ▶ try {
Subroutine __ANON__: not called CC=2 SCAR=17.9
72 0 $self->repo->svp_begin;
73 0 my ($dist, $did_update, $did_update_prereqs) = $self->update($target);
74 0 ▶ push @{$self->affected}, $dist if $did_update;
Branch: 1 branch
BranchTrueFalseTotal
if $did_update 0 0 0
75 }
76 0 ▶ catch {
Subroutine __ANON__: not called CC=2 SCAR=17.9
77 0 ▶ throw $_ unless $self->no_fail;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->no_fail 0 0 0
78 0 $self->result->failed( because => $_ );
79  
80 0 $self->repo->svp_rollback;
81  
82 0 $self->error($_);
83 0 $self->error("Target $target failed...continuing anyway");
84 }
85 0 ▶ finally {
Subroutine __ANON__: not called CC=2 SCAR=17.9
86 0 my ($error) = @_;
87 0 ▶ $self->repo->svp_release unless $error;
Branch: 1 branch
BranchTrueFalseTotal
unless $error 0 0 0
88 0 };
89 }
90  
91 0 $self->chrome->progress_done;
92  
93 0 return $self;
94 }
95  
96 #------------------------------------------------------------------------------
97  
98 0 ▶sub compute_targets {
Subroutine compute_targets: not called CC=4 SCAR=30.0
Pod undocumented
99 0 my ($self) = @_;
100  
101 0 my $stack = $self->stack;
102  
103 0 ▶ return map {$_->main_module->as_target->unversioned} $stack->distributions
Branch: 1 branch
BranchTrueFalseTotal
if $self->all 0 0 0
104 if $self->all;
105  
106 0 ▶ return map {$_->main_module->as_target->unversioned} $stack->roots
Branch: 1 branch
BranchTrueFalseTotal
if $self->roots 0 0 0
107 if $self->roots;
108  
109 0 ▶ return $self->targets
Branch: 1 branch
BranchTrueFalseTotal
if $self->targets 0 0 0
110 if $self->targets;
111  
112 0 throw "No targets specified";
113 }
114  
115  
116 #------------------------------------------------------------------------------
117 # TODO: Should we only update packages from foreign dists?
118 # TODO: Skip pinned targets unless --force
119 # TODO: Should pins be preserved?
120  
121  
122 0 ▶sub update {
Subroutine update: not called CC=9 SCAR=45.0
Pod undocumented
123 0 my ($self, $target) = @_;
124  
125 0 my $pkg_name = $target->name;
126 0 my $stack = $self->stack;
127  
128 0 ▶ throw ("Package $pkg_name is not on stack $stack")
Branch: 1 branch
BranchTrueFalseTotal
unless my $reg = $stack->head->registrations->find({"package_name", $pkg_name}) 0 0 0
129 unless my $reg = $stack->head->registrations->find({package_name => $pkg_name});
130  
131 0 my $current_dist = $reg->distribution;
132 0 my $current_pkg = $reg->package;
133  
134 0 ▶ if ($reg->is_pinned && not $self->force) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reg->is_pinned and not $self->force) 0 0 0
Condition0%0/3
$reg->is_pinned and not $self->force
!ll&&!rl&&r
000
MC/DC0%0/2
$reg->is_pinned and not $self->force
$reg->is_pinned not $self->force
Truth table0%0/3
A and not(B)
A= $reg->is_pinnedB= not $self->force
ABresult
0X0
100
111
135 0 $self->notice("Skipping package $pkg_name because it is pinned to $current_dist");
136 0 return ($current_dist, 0, 0);
137 }
138  
139 0 ▶ if ($current_dist->is_local && !$self->all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($current_dist->is_local and not $self->all) 0 0 0
Condition0%0/3
$current_dist->is_local and not $self->all
!ll&&!rl&&r
000
MC/DC0%0/2
$current_dist->is_local and not $self->all
$current_dist->is_local not $self->all
Truth table0%0/3
A and not(B)
A= $current_dist->is_localB= not $self->all
ABresult
0X0
100
111
140 0 $self->notice("Skipping local package $pkg_name");
141 0 return ($current_dist, 0, 0);
142 }
143  
144 # Now go look for a newer version...
145 0 my $latest_pkg = $self->repo->locate(target => $target);
146  
147 0 ▶ if (!$latest_pkg and !$current_dist->is_local) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($latest_pkg or $current_dist->is_local) 0 0 0
Condition0%0/3
$latest_pkg or $current_dist->is_local
l!l&&r!l&&!r
000
MC/DC0%0/2
$latest_pkg or $current_dist->is_local
$latest_pkg $current_dist->is_local
Truth table0%0/3
A or B
A= $latest_pkgB= $current_dist->is_local
ABresult
1X1
011
000
148 0 $self->warning("No upstream version of $pkg_name was found");
149 0 return ($current_dist, 0, 0);
150 }
151  
152 0 my $latest_pkg_version = $latest_pkg->{version};
153 0 my $current_pkg_version = $current_pkg->version;
154  
155 0 ▶ if ($latest_pkg_version <= $current_pkg_version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($latest_pkg_version <= $current_pkg_version) 0 0 0
156 0 $self->notice( "Package $pkg_name~$current_pkg_version is up to date");
157 0 return ($current_dist, 0, 0);
158 }
159  
160 # Finally, we update...
161 0 $self->notice("Updating $pkg_name to $latest_pkg_version on stack $stack");
162 0 my %target_args = (name => $pkg_name, version => $latest_pkg_version);
163 0 my $new_target = Pinto::Target::Package->new(%target_args);
164 0 return $self->pull(target => $new_target);
165  
166 }
167  
168 #------------------------------------------------------------------------------
169  
170 1 __PACKAGE__->meta->make_immutable;
171  
172 #------------------------------------------------------------------------------
173  
174 1 1;
175  
176 __END__
« blib/lib/Pinto/Schema/Result/Distribution.pm ↑ Summary blib/lib/Pinto/Action/Stacks.pm »