Carmel/App.pm

filter: Statementstmt 16.5% 65 / 392 Branchbran 1.0% 1 / 98 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 24.1% 21 / 87 Podpod 0.0% 0 / 42 totaltotal 13.2% 87 / 658 CC 74 SCAR 29.7
CC
74
Cov
13%
update_or_install
90.0
cmd_inject
72.0
__ANON__
42.0
CRAP 19.5
« Carmel/Builder.pm ↑ Summary Carmel/ProgressBar.pm »
1 package Carmel::App;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Carmel;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carmel::Runner;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carmel::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carmel::CPANfile;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carmel::Environment;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carmel::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carmel::Resolver;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Carmel::ProgressBar qw(progress);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Config qw(%Config);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use CPAN::Meta::Requirements;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::pushd qw(pushd);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Module::CPANfile;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Module::Metadata;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Pod::Usage ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # prefer Parse::CPAN::Meta in XS, PP order with JSON.pm
25 $ENV{PERL_JSON_BACKEND} = 1
26 1 ▶ unless defined $ENV{PERL_JSON_BACKEND};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"PERL_JSON_BACKEND"} 1 0 1
27  
28 1 ▶use Class::Tiny {
Subroutine BEGIN: called CC=1 SCAR=0.2
29 0 ▶ verbose => sub { 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 1 };
31  
32 0 ▶sub parse_options {
Subroutine parse_options: not called CC=4 SCAR=30.0
Pod undocumented
33 0 my($self, $args) = @_;
34  
35 0 ▶ return if $args->[0] && $args->[0] eq 'exec';
Branch: 1 branch
BranchTrueFalseTotal
if $args->[0] and $args->[0] eq "exec" 0 0 0
Condition0%0/3
$args->[0] and $args->[0] eq "exec"
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] and $args->[0] eq "exec"
$args->[0] $args->[0] eq "exec"
Truth table0%0/3
A and B
A= $args->[0]B= $args->[0] eq "exec"
ABresult
0X0
100
111
36  
37 0 my $cmd;
38 0 my $parser = Getopt::Long::Parser->new(
39 config => [ "no_ignore_case", "pass_through" ],
40 );
41 $parser->getoptionsfromarray(
42 $args,
43 0 ▶ "h|help" => sub { $cmd = 'help' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
44 0 ▶ "version" => sub { $cmd = 'version' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 ▶ "v|verbose!" => sub { $Carmel::DEBUG = $self->verbose($_[1]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 );
47  
48 0 ▶ unshift @$args, $cmd if $cmd;
Branch: 1 branch
BranchTrueFalseTotal
if $cmd 0 0 0
49 }
50  
51 0 ▶sub run {
Subroutine run: not called CC=4 SCAR=30.0
Pod undocumented
52 0 my($self, @args) = @_;
53  
54 0 $self->parse_options(\@args);
55  
56 0 ▶ my $cmd = shift @args || 'install';
Condition0%0/2
shift @args || 'install'
l!l
00
MC/DC0%0/1
shift @args || 'install'
shift @args
Truth table0%0/2
A
A= shift @args
Aresult
11
00
57 0 ▶ my $call = $self->can("cmd_$cmd")
Branch: 1 branch
BranchTrueFalseTotal
my $call = $self->can("cmd_$cmd") or die "Can't find command '${cmd}': run `carmel help` to see the list of commands.\n" 0 0 0
58 or die "Can't find command '$cmd': run `carmel help` to see the list of commands.\n";
59  
60 0 ▶ if ($cmd eq 'run') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "run") 0 0 0
61 0 return $self->cmd_run(@args);
62 }
63  
64 0 my $code = 0;
65 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 $self->$call(@args);
67 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 warn $_;
69 0 $code = 1;
70 0 };
71  
72 0 return $code;
73 }
74  
75 0 ▶sub env {
Subroutine env: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my $self = shift;
77 0 ▶ $self->{env} ||= Carmel::Environment->new;
Condition0%0/3
$self->{"env"} ||= "Carmel::Environment"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"env"} ||= "Carmel::Environment"->new
$self->{"env"} "Carmel::Environment"->new
Truth table0%0/3
A ||= B
A= $self->{"env"}B= "Carmel::Environment"->new
ABresult
1X1
011
000
78 }
79  
80 0 ▶sub cmd_help {
Subroutine cmd_help: not called CC=1 SCAR=6.9
Pod undocumented
81 0 my $self = shift;
82 0 print "Carmel version $Carmel::VERSION\n\n";
83 0 Pod::Usage::pod2usage(1);
84 }
85  
86 0 ▶sub cmd_version {
Subroutine cmd_version: not called CC=1 SCAR=6.9
Pod undocumented
87 0 my $self = shift;
88 0 print "Carmel version $Carmel::VERSION\n";
89 }
90  
91 0 ▶sub cmd_inject {
Subroutine cmd_inject: not called CC=8 SCAR=42.8
Pod undocumented
92 0 my($self, @args) = @_;
93  
94 0 my $reqs = CPAN::Meta::Requirements->new;
95 0 for my $arg (@args) {
96 0 my($module, $version) = split /@/, $arg, 2;
97 0 ▶ $reqs->add_string_requirement($module, $version ? "== $version" : 0);
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
98 }
99  
100 0 my $cpanfile = Module::CPANfile->from_prereqs({
101 runtime => {
102 requires => $reqs->as_string_hash,
103 },
104 });
105  
106 # FIXME: $builder->install() reads mirror info from cpanfile_path
107 0 my $path = Path::Tiny->tempfile;
108 0 $cpanfile->save($path);
109  
110 0 my @artifacts = $self->builder(cpanfile => $cpanfile, cpanfile_path => $path)->install;
111  
112 0 my @failed;
113 MODULE:
114 0 for my $module ($reqs->required_modules) {
115 0 my $want = $reqs->requirements_for_module($module);
116 0 for my $artifact (@artifacts) {
117 0 ▶ if ($artifact->provides->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($artifact->provides->{$module}) 0 0 0
118 0 my $version = $artifact->version_for($module);
119 0 ▶ $reqs->accepts_module($module => $version)
Branch: 1 branch
BranchTrueFalseTotal
$reqs->accepts_module($module, $version) or die "Installed version for $module ($version) doesn't satisfy the requirement: $want\n" 0 0 0
120 or die "Installed version for $module ($version) doesn't satisfy the requirement: $want\n";
121 0 next MODULE;
122 }
123 }
124  
125 0 push @failed, $module;
126 }
127  
128 0 ▶ if (@failed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@failed) 0 0 0
129 0 die "Couldn't install module(s): ", join(", ", @failed), "\n";
130 }
131 }
132  
133 0 ▶sub cmd_pin {
Subroutine cmd_pin: not called CC=1 SCAR=6.9
Pod undocumented
134 0 my($self, @args) = @_;
135 0 die "carmel pin is deprecated. Use `carmel update @args` instead\n";
136 }
137  
138 0 ▶sub cmd_update {
Subroutine cmd_update: not called CC=2 SCAR=17.9
Pod undocumented
139 0 my($self, @args) = @_;
140  
141 0 ▶ my $snapshot = $self->env->snapshot
Branch: 1 branch
BranchTrueFalseTotal
my $snapshot = $self->env->snapshot or die "Can't run carmel update without snapshot. Run `carmel install` first.\n" 0 0 0
142 or die "Can't run carmel update without snapshot. Run `carmel install` first.\n";
143  
144 0 print "---> Checking updates...\n";
145  
146 0 $self->update_or_install($snapshot, @args);
147 }
148  
149 0 ▶sub update_or_install {
Subroutine update_or_install: not called CC=9 SCAR=45.0
Pod undocumented
150 0 my($self, $snapshot, @args) = @_;
151  
152 0 my $builder = $self->builder;
153 0 my $requirements = $self->requirements;
154  
155 0 ▶ my $check = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
156 0 my($module, $pathname, $in_args, $version) = @_;
157  
158 0 ▶ return if $module eq 'perl';
Branch: 1 branch
BranchTrueFalseTotal
if $module eq "perl" 0 0 0
159  
160 0 my $dist = $builder->search_module($module, $version);
161 0 ▶ unless ($dist) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dist) 0 0 0
162 0 ▶ if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) { } 0 0 0
163 0 die "Can't find $module ($version) on CPAN\n";
164 } else {
165 # workaround bad main package e.g. LWP => libwww::perl
166 0 warn "Can't find $module on CPAN\n";
167 0 return;
168 }
169 }
170  
171 # non-dual core module like "strict.pm"
172 # TODO should be $dist->is_perl
173 0 ▶ return if $dist->name =~ /^perl-5\.\d+\.\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $dist->name =~ /^perl-5\.\d+\.\d+$/ 0 0 0
174  
175 0 ▶ if (defined $version) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version) { } 0 0 0
176 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
177 0 $requirements->add_string_requirement($module, $version);
178 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
179 0 my($err) = /illegal requirements(?: .*?): (.*) at/;
180 0 my $old = $requirements->requirements_for_module($module);
181 0 die "Requested version for $module '$version' conflicts with version required in cpanfile '$old': $err\n";
182 0 };
183 } else {
184 0 my $want_ver = $dist->version_for($module);
185 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
186 0 $requirements->add_string_requirement($module, $want_ver);
187 0 ▶ } catch {
Subroutine __ANON__: not called CC=2 SCAR=17.9
188 # there's an update but it conflicts with specs in cpanfile, ignoring
189 0 ▶ if ($in_args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_args) 0 0 0
190 0 my($err) = /illegal requirements(?: .*?): (.*) at/;
191 0 my $old = $requirements->requirements_for_module($module);
192 0 die "The update for $module '$want_ver' conflicts with version required in cpanfile '$old' $err\n";
193 }
194 0 };
195 }
196 0 };
197  
198 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) { } 0 0 0
199 0 for my $arg (@args) {
200 0 my($module, $version) = split '@', $arg, 2;
201 0 ▶ my $dist = $snapshot ? $snapshot->find($module) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$snapshot ? : 0 0 0
202 0 ▶ if ($dist) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dist) { } 0 0 0
elsif (defined $requirements->requirements_for_module($module)) { } 0 0 0
203 0 ▶ $check->($module, $dist->pathname, 1, $version ? "== $version" : undef);
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
204 } elsif (defined $requirements->requirements_for_module($module)) {
205 0 ▶ $check->($module, '', 1, $version ? "== $version" : undef);
Branch: 1 branch
BranchTrueFalseTotal
$version ? : 0 0 0
206 } else {
207 0 die "$module is not found in cpanfile or cpanfile.snapshot\n";
208 }
209 }
210 } else {
211 0 my $missing = $requirements->clone;
212  
213 0 my @checks;
214 my $resolver = $self->resolver(
215 root => $self->requirements->clone,
216 snapshot => $snapshot,
217 0 ▶ found => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
218 0 my $artifact = shift;
219 0 for my $pkg (keys %{$artifact->provides}) {
220 0 $missing->clear_requirement($pkg);
221 }
222 0 push @checks, [ $artifact->package, $artifact->install->{pathname}, 0 ];
223 },
224 0 ▶ missing => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
225 0 my($module, $want_version) = @_;
226 0 $missing->add_string_requirement($module => $want_version);
227 },
228 0 );
229 0 $resolver->resolve;
230  
231 # snapshot not supplied (first carmel install), or
232 # specified in cpanfile but not in snapshot, possibly core module
233 0 for my $module ($missing->required_modules) {
234 0 push @checks, [ $module, '', 0 ];
235 }
236  
237 0 ▶ progress \@checks, sub { $check->(@{$_[0]}) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
238 }
239  
240 # rebuild the snapshot
241 0 $self->update_dependencies($requirements, $snapshot);
242 }
243  
244 0 ▶sub cmd_install {
Subroutine cmd_install: not called CC=3 SCAR=24.8
Pod undocumented
245 0 my($self, @args) = @_;
246  
247 0 ▶ die "Usage: carmel install\n" if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 0 0 0
248  
249 0 my $snapshot = $self->env->snapshot;
250 0 ▶ if ($snapshot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($snapshot) { } 0 0 0
251 0 $self->update_dependencies($self->requirements, $snapshot);
252 } else {
253 0 print "---> Installing modules...\n";
254 0 $self->update_or_install($snapshot);
255 }
256 }
257  
258 0 ▶sub update_dependencies {
Subroutine update_dependencies: not called CC=1 SCAR=6.9
Pod undocumented
259 0 my($self, $root_reqs, $snapshot) = @_;
260  
261 0 my @artifacts = $self->install($root_reqs, $snapshot);
262 0 $self->dump_bootstrap(\@artifacts);
263 0 $self->save_snapshot(\@artifacts);
264 }
265  
266 0 ▶sub resolve_dependencies {
Subroutine resolve_dependencies: not called CC=1 SCAR=6.9
Pod undocumented
267 0 my($self, $root_reqs, $missing, $snapshot) = @_;
268  
269 0 my @artifacts;
270 $self->resolver(
271 root => $root_reqs,
272 snapshot => $snapshot,
273 0 ▶ found => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
274 0 my $artifact = shift;
275 0 ▶ printf "Using %s (%s)\n", $artifact->package, $artifact->version || '0';
Condition0%0/2
$artifact->version || '0'
l!l
00
MC/DC0%0/1
$artifact->version || '0'
$artifact->version
Truth table0%0/2
A
A= $artifact->version
Aresult
11
00
276 0 push @artifacts, $artifact;
277 },
278 0 ▶ missing => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
279 0 my($module, $want_version) = @_;
280 0 $missing->add_string_requirement($module => $want_version);
281 },
282 0 )->resolve;
283  
284 0 return @artifacts;
285 }
286  
287 0 ▶sub is_identical_requirement {
Subroutine is_identical_requirement: not called CC=2 SCAR=17.9
Pod undocumented
288 0 my($self, $old, $new) = @_;
289  
290 0 ▶ return unless $old;
Branch: 1 branch
BranchTrueFalseTotal
unless $old 0 0 0
291  
292 # not super accurate but enough
293 0 join(',', sort $old->required_modules) eq join(',', sort $new->required_modules);
294 }
295  
296 0 ▶sub try_install {
Subroutine try_install: not called CC=4 SCAR=30.0
Pod undocumented
297 0 my($self, $root_reqs, $snapshot) = @_;
298  
299 0 my $prev;
300 0 while (1) {
301 0 my $missing = CPAN::Meta::Requirements->new;
302 0 my @artifacts = $self->resolve_dependencies($root_reqs, $missing, $snapshot);
303  
304 0 ▶ if (!$missing->required_modules) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($missing->required_modules) 0 0 0
305 0 return @artifacts;
306 }
307  
308 0 ▶ if ($self->is_identical_requirement($prev, $missing)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_identical_requirement($prev, $missing)) 0 0 0
309 0 my $prereqs = $missing->as_string_hash;
310 0 ▶ my $requirements = join ", ", map "$_ => @{[ $prereqs->{$_} || '0' ]}", keys %$prereqs;
Condition0%0/2
$prereqs->{$_} || '0'
l!l
00
MC/DC0%0/1
$prereqs->{$_} || '0'
$prereqs->{$_}
Truth table0%0/2
A
A= $prereqs->{$_}
Aresult
11
00
311 0 die "Can't find an artifact for $requirements\n" .
312 "You need to run `carmel install` first to get the modules installed and artifacts built.\n";
313 }
314  
315 0 $prev = $missing;
316  
317 0 my $cpanfile = Module::CPANfile->from_prereqs({
318 runtime => {
319 requires => $missing->as_string_hash,
320 },
321 });
322 0 print "---> Installing new dependencies: ", join(", ", $missing->required_modules), "\n";
323 0 my $builder = $self->builder(cpanfile => $cpanfile, snapshot => $snapshot);
324 0 $builder->install;
325 }
326 }
327  
328 0 ▶sub install {
Subroutine install: not called CC=1 SCAR=6.9
Pod undocumented
329 0 my($self, $root_reqs, $snapshot) = @_;
330  
331 0 my @artifacts = $self->try_install($root_reqs, $snapshot);
332  
333 # $root_reqs has been mutated at this point. Reload requirements
334 printf "---> Complete! %d cpanfile dependencies. %d modules installed.\n",
335 0 scalar(grep { $_ ne 'perl' } $self->requirements->required_modules), scalar(@artifacts);
336  
337 0 return @artifacts;
338 }
339  
340 0 ▶sub cmd_reinstall {
Subroutine cmd_reinstall: not called CC=6 SCAR=37.4
Pod undocumented
341 0 my($self, @args) = @_;
342  
343 0 ▶ my @modules = @args ? @args : $self->requirements->required_modules;
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 0 0
344  
345 0 ▶ my $snapshot = $self->env->snapshot
Branch: 1 branch
BranchTrueFalseTotal
my $snapshot = $self->env->snapshot or die "Can't run carmel reinstall without snapshot. Run `carmel install` first.\n" 0 0 0
346 or die "Can't run carmel reinstall without snapshot. Run `carmel install` first.\n";
347  
348 0 my $reqs = CPAN::Meta::Requirements->new;
349 0 for my $module (@modules) {
350 0 ▶ if (my $dist = $snapshot->find($module)) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $dist = $snapshot->find($module)) { } 0 0 0
elsif (@args) { } 0 0 0
351 0 $reqs->add_string_requirement($module, $dist->version_for($module));
352 } elsif (@args) {
353 0 die "$module is not found in cpanfile.snapshot\n";
354 }
355 }
356  
357 0 my $cpanfile = Module::CPANfile->from_prereqs({
358 runtime => {
359 requires => $reqs->as_string_hash,
360 },
361 });
362  
363 0 $self->builder(cpanfile => $cpanfile, snapshot => $snapshot)->install;
364 0 $self->cmd_install;
365 }
366  
367 0 ▶sub builder {
Subroutine builder: not called CC=1 SCAR=6.9
Pod undocumented
368 0 my($self, @args) = @_;
369  
370 Carmel::Builder->new(
371 repository_base => $self->env->repository_base,
372 cpanfile_path => $self->env->cpanfile->path,
373 0 ▶ collect_artifact => sub { $self->env->repo->import_artifact(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
374 0 @args,
375 );
376 }
377  
378 0 ▶sub quote {
Subroutine quote: not called CC=2 SCAR=17.9
Pod undocumented
379 0 my $indent = shift;
380 0 $indent = " " x $indent;
381  
382 0 require Data::Dumper;
383 0 my $val = Data::Dumper->new([transform(@_)], [])
384 ->Sortkeys(1)->Terse(1)->Indent(1)->Dump;
385  
386 0 chomp $val;
387 0 ▶ $val =~ s/^/$indent/mg if $indent;
Branch: 1 branch
BranchTrueFalseTotal
if $indent 0 0 0
388 0 $val =~ s/^ *//;
389 0 $val;
390 }
391  
392 0 ▶sub transform {
Subroutine transform: not called CC=3 SCAR=24.8
Pod undocumented
393 0 my $data = shift;
394  
395 # stringify elements
396 0 ▶ if (ref $data eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'ARRAY') { } 0 0 0
elsif (ref $data eq 'HASH') { } 0 0 0
397 0 [map transform($_), @$data];
398 } elsif (ref $data eq 'HASH') {
399 0 my %value = map { $_ => transform($data->{$_}) } keys %$data;
400 0 \%value;
401 } else {
402 0 "$data";
403 }
404 }
405  
406 0 ▶sub save_snapshot {
Subroutine save_snapshot: not called CC=2 SCAR=17.9
Pod undocumented
407 0 my($self, $artifacts) = @_;
408  
409 0 require Carton::Snapshot;
410 0 require Carton::Dist;
411  
412 0 my $snapshot = Carton::Snapshot->new(path => $self->env->snapshot_path);
413  
414 0 for my $artifact (@$artifacts) {
415 my $dist = Carton::Dist->new(
416 name => $artifact->distname,
417 pathname => $artifact->install->{pathname},
418 0 provides => $artifact->provides,
419 version => $artifact->version,
420 # compatibility with Carton snapshot
421 requirements => $artifact->requirements_for([qw( configure build runtime )], ['requires']),
422 );
423 0 $snapshot->add_distribution($dist);
424 }
425  
426 0 $snapshot->save;
427 }
428  
429 0 ▶sub dump_bootstrap {
Subroutine dump_bootstrap: not called CC=4 SCAR=30.0
Pod undocumented
430 0 my($self, $artifacts) = @_;
431  
432 0 my @inc = map $_->nonempty_libs, @$artifacts;
433 0 my @path = map $_->nonempty_paths, @$artifacts;
434  
435 0 my(%execs);
436 0 for my $artifact (@$artifacts) {
437 0 my %bins = $artifact->executables;
438 0 ▶ $execs{$artifact->package} = \%bins if %bins;
Branch: 1 branch
BranchTrueFalseTotal
if %bins 0 0 0
439 }
440  
441 0 my %modules;
442 0 for my $artifact (@$artifacts) {
443 0 %modules = (%modules, $artifact->module_files);
444 }
445  
446 0 my $prereqs = $self->env->cpanfile->load->prereqs->as_string_hash;
447 0 my $package = "Carmel::MySetup"; # hide from PAUSE
448  
449 0 my $file = Path::Tiny->new(".carmel/MySetup.pm");
450 0 $file->parent->mkpath;
451 0 $file->spew(<<EOF);
452 # DO NOT EDIT! Auto-generated via carmel install.
453 package $package;
454  
455 our %environment = (
456 0 'inc' => @{[ quote 2, \@inc ]},
457 0 'path' => @{[ quote 2, \@path ]},
458 0 'execs' => @{[ quote 2, \%execs ]},
459 0 'base' => @{[ quote(2, Path::Tiny->cwd) ]},
460 0 'modules' => @{[ quote 2, \%modules ]},
461 0 'prereqs' => @{[ quote 2, $prereqs ]},
462 );
463  
464 1;
465 EOF
466 }
467  
468 0 ▶sub cmd_export {
Subroutine cmd_export: not called CC=1 SCAR=6.9
Pod undocumented
469 0 my($self) = @_;
470 0 my %env = Carmel::Runner->new->env;
471 0 print "export ", join(" ", map qq($_="$env{$_}"), sort keys %env), "\n";
472 }
473  
474 0 ▶sub cmd_env {
Subroutine cmd_env: not called CC=1 SCAR=6.9
Pod undocumented
475 0 my($self) = @_;
476 0 my %env = Carmel::Runner->new->env;
477 0 print join "", map qq($_=$env{$_}\n), sort keys %env;
478 }
479  
480 0 ▶sub cmd_run {
Subroutine cmd_run: not called CC=1 SCAR=6.9
Pod undocumented
481 0 my($self, @args) = @_;
482 0 Carmel::Runner->new->run(@args);
483 }
484  
485 # Usually carmel exec is handled in carmel script, not here
486 0 ▶sub cmd_exec {
Subroutine cmd_exec: not called CC=1 SCAR=6.9
Pod undocumented
487 0 my($self, @args) = @_;
488 0 Carmel::Runner->new->execute(@args);
489 }
490  
491 0 ▶sub cmd_find {
Subroutine cmd_find: not called CC=4 SCAR=30.0
Pod undocumented
492 0 my($self, $module, $requirement) = @_;
493  
494 0 ▶ my @artifacts = $self->env->repo->find_all($module, $requirement || '0');
Condition0%0/2
$requirement || '0'
l!l
00
MC/DC0%0/1
$requirement || '0'
$requirement
Truth table0%0/2
A
A= $requirement
Aresult
11
00
495 0 for my $artifact (@artifacts) {
496 0 ▶ printf "%s (%s) in %s\n", $artifact->package, $artifact->version || '0', $artifact->path;
Condition0%0/2
$artifact->version || '0'
l!l
00
MC/DC0%0/1
$artifact->version || '0'
$artifact->version
Truth table0%0/2
A
A= $artifact->version
Aresult
11
00
497 }
498 }
499  
500 0 ▶sub cmd_show {
Subroutine cmd_show: not called CC=4 SCAR=30.0
Pod undocumented
501 0 my($self, $module) = @_;
502  
503 0 ▶ $module or die "Usage: carmel show Module\n";
Branch: 1 branch
BranchTrueFalseTotal
$module or die "Usage: carmel show Module\n" 0 0 0
504  
505 0 my $artifact = $self->artifact_for($module);
506 0 ▶ printf "%s (%s) in %s\n", $artifact->package, $artifact->version || '0', $artifact->path
Branch: 1 branch
BranchTrueFalseTotal
if $artifact 0 0 0
Condition0%0/2
$artifact->version || '0'
l!l
00
MC/DC0%0/1
$artifact->version || '0'
$artifact->version
Truth table0%0/2
A
A= $artifact->version
Aresult
11
00
507 if $artifact;
508 }
509  
510 0 ▶sub cmd_info {
Subroutine cmd_info: not called CC=1 SCAR=6.9
Pod undocumented
511 0 my $self = shift;
512 0 $self->cmd_show(@_);
513 }
514  
515 0 ▶sub cmd_list {
Subroutine cmd_list: not called CC=3 SCAR=24.8
Pod undocumented
516 0 my $self = shift;
517  
518 0 my @artifacts;
519 0 ▶ $self->resolve(sub { push @artifacts, $_[0] });
Subroutine __ANON__: not called CC=1 SCAR=6.9
520  
521 0 for my $artifact (sort { $a->package cmp $b->package } @artifacts) {
522 0 ▶ printf "%s (%s)\n", $artifact->package, $artifact->version || '0';
Condition0%0/2
$artifact->version || '0'
l!l
00
MC/DC0%0/1
$artifact->version || '0'
$artifact->version
Truth table0%0/2
A
A= $artifact->version
Aresult
11
00
523 }
524 }
525  
526 0 ▶sub cmd_look {
Subroutine cmd_look: not called CC=3 SCAR=24.8
Pod undocumented
527 0 my($self, $module) = @_;
528  
529 0 ▶ $module or die "Usage: carmel look Module\n";
Branch: 1 branch
BranchTrueFalseTotal
$module or die "Usage: carmel look Module\n" 0 0 0
530  
531 my $shell = $ENV{SHELL}
532 0 ▶ or die "Can't determine shell from SHELL variable\n";
Branch: 1 branch
BranchTrueFalseTotal
my $shell = $ENV{"SHELL"} or die "Can't determine shell from SHELL variable\n" 0 0 0
533  
534 0 my $artifact = $self->artifact_for($module);
535  
536 0 my $dir = pushd $artifact->path;
537 0 system $shell;
538 }
539  
540 0 ▶sub cmd_diff {
Subroutine cmd_diff: not called CC=4 SCAR=30.0
Pod undocumented
541 0 my $self = shift;
542  
543 0 my $snapshot_path = $self->env->snapshot_path->relative;
544  
545 # Don't check if .git exists, and let git(2) handle the error
546  
547 0 ▶ if ($ENV{PERL_CARMEL_USE_DIFFTOOL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'PERL_CARMEL_USE_DIFFTOOL'}) { } 0 0 0
548 0 my $cmd = 'carmel difftool';
549 0 ▶ $cmd .= ' -v' if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
550  
551 0 system 'git', 'difftool', '--no-prompt',
552 '--extcmd', $cmd, $snapshot_path;
553 } else {
554 0 require Carmel::Difftool;
555  
556 0 ▶ my $content = `git show HEAD:$snapshot_path`
Branch: 1 branch
BranchTrueFalseTotal
my $content = `git show HEAD:$snapshot_path` or die "Can't retrieve snapshot content (not in git repository?)\n" 0 0 0
557 or die "Can't retrieve snapshot content (not in git repository?)\n";
558 0 my $path = Path::Tiny->tempfile;
559 0 $path->spew($content);
560  
561 0 my $diff = Carmel::Difftool->new;
562 0 $diff->diff($path, $snapshot_path);
563 }
564 }
565  
566 0 ▶sub cmd_difftool {
Subroutine cmd_difftool: not called CC=1 SCAR=6.9
Pod undocumented
567 0 my($self, @args) = @_;
568  
569 0 require Carmel::Difftool;
570  
571 0 my $diff = Carmel::Difftool->new;
572 0 $diff->diff(@args);
573 }
574  
575 0 ▶sub resolve {
Subroutine resolve: not called CC=1 SCAR=6.9
Pod undocumented
576 0 my($self, $cb) = @_;
577 0 $self->resolver(found => $cb)->resolve;
578 }
579  
580 0 ▶sub resolver {
Subroutine resolver: not called CC=1 SCAR=6.9
Pod undocumented
581 0 my($self, @args) = @_;
582  
583 Carmel::Resolver->new(
584 repo => $self->env->repo,
585 root => $self->requirements,
586 snapshot => scalar $self->env->snapshot,
587 0 ▶ missing => sub { $self->missing_default(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
588 0 @args,
589 );
590 }
591  
592 0 ▶sub missing_default {
Subroutine missing_default: not called CC=1 SCAR=6.9
Pod undocumented
593 0 my($self, $module, $want_version, $depth) = @_;
594 0 die "Can't find an artifact for $module => $want_version\n" .
595 "You need to run `carmel install` first to get the modules installed and artifacts built.\n";
596 }
597  
598 0 ▶sub artifact_for {
Subroutine artifact_for: not called CC=3 SCAR=24.8
Pod undocumented
599 0 my($self, $module) = @_;
600  
601 0 my $found;
602 0 eval {
603 0 ▶ $self->resolve(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
604 0 my $artifact = shift;
605 0 ▶ if (exists $artifact->provides->{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $artifact->provides->{$module}) 0 0 0
606 0 $found = $artifact;
607 0 die "__FOUND__\n";
608 }
609 0 });
610 0 die "Can't find a module named '$module' in the cpanfile dependencies.\n";
611 };
612  
613 0 ▶ die $@ if $@ && $@ ne "__FOUND__\n";
Branch: 1 branch
BranchTrueFalseTotal
if $@ and $@ ne "__FOUND__\n" 0 0 0
Condition0%0/3
$@ and $@ ne "__FOUND__\n"
!ll&&!rl&&r
000
MC/DC0%0/2
$@ and $@ ne "__FOUND__\n"
$@ $@ ne "__FOUND__\n"
Truth table0%0/3
A and B
A= $@B= $@ ne "__FOUND__\n"
ABresult
0X0
100
111
614 0 return $found;
615 }
616  
617 0 ▶sub cmd_tree {
Subroutine cmd_tree: not called CC=1 SCAR=6.9
Pod undocumented
618 0 my($self) = @_;
619  
620 0 ▶ $self->resolve(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
621 0 my($artifact, $depth) = @_;
622 0 ▶ printf "%s%s (%s)\n", (" " x $depth), $artifact->package, $artifact->version || '0';
Condition0%0/2
$artifact->version || '0'
l!l
00
MC/DC0%0/1
$artifact->version || '0'
$artifact->version
Truth table0%0/2
A
A= $artifact->version
Aresult
11
00
623 0 });
624 }
625  
626 0 ▶sub cmd_rollout {
Subroutine cmd_rollout: not called CC=2 SCAR=17.9
Pod undocumented
627 0 my $self = shift;
628  
629 0 my @artifacts;
630 0 ▶ $self->resolve(sub { push @artifacts, $_[0] });
Subroutine __ANON__: not called CC=1 SCAR=6.9
631  
632 # TODO safe atomic rename
633 0 my $install_base = Path::Tiny->new("local")->absolute;
634 0 ▶ $install_base->remove_tree({ safe => 0 }) if $install_base->exists;
Branch: 1 branch
BranchTrueFalseTotal
if $install_base->exists 0 0 0
635  
636 0 $self->builder->rollout($install_base, \@artifacts);
637  
638 0 $install_base->child(".carmel")->touch;
639 }
640  
641 0 ▶sub cmd_package {
Subroutine cmd_package: not called CC=6 SCAR=37.4
Pod undocumented
642 0 my $self = shift;
643  
644 0 my $index = $self->build_index;
645  
646 0 my $source_base = $self->env->repository_base->child('cache');
647 0 my $target_base = Path::Tiny->new('vendor/cache');
648  
649 0 my %done;
650 my @found;
651 0 for my $package ($index->packages) {
652 0 ▶ next if $done{$package->pathname}++;
Branch: 1 branch
BranchTrueFalseTotal
if $done{$package->pathname}++ 0 0 0
653  
654 0 my $source = $source_base->child('authors/id', $package->pathname);
655 0 my $target = $target_base->child('authors/id', $package->pathname);
656  
657 0 ▶ if ($source->exists) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->exists) { } 0 0 0
658 0 ▶ push @found, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
659 0 print "Copying ", $package->pathname, "\n";
660 0 $target->parent->mkpath;
661 0 $source->copy($target);
662 0 };
663 } else {
664 0 die sprintf "%s not found in %s.\n" .
665 "Run `carmel install` to fix this. If that didn't resolve the issue, try removing %s\n",
666 $package->pathname, $source_base, $self->env->repository_base;
667 }
668 }
669  
670 0 for my $copy (@found) {
671 0 $copy->();
672 }
673  
674 0 require IO::Compress::Gzip;
675 0 my $index_file = $target_base->child('modules/02packages.details.txt.gz');
676 0 $index_file->parent->mkpath;
677  
678 0 warn "Writing $index_file\n";
679 0 ▶ my $out = IO::Compress::Gzip->new($index_file->openw)
Branch: 1 branch
BranchTrueFalseTotal
my $out = "IO::Compress::Gzip"->new($index_file->openw) or die "gzip failed: $IO::Compress::Gzip::GzipError" 0 0 0
680 or die "gzip failed: $IO::Compress::Gzip::GzipError";
681 0 $index->write($out);
682  
683 0 print "---> Complete! ", scalar(@found), " distributions are packaged in vendor/cache\n";
684 }
685  
686 0 ▶sub cmd_index {
Subroutine cmd_index: not called CC=1 SCAR=6.9
Pod undocumented
687 0 my $self = shift;
688 0 $self->build_index->write(*STDOUT);
689 }
690  
691 0 ▶sub build_index {
Subroutine build_index: not called CC=1 SCAR=6.9
Pod undocumented
692 0 my $self = shift;
693  
694 0 require Carton::Index;
695 0 require Carton::Package;
696  
697 0 my $index = Carton::Index->new(generator => "Carmel $Carmel::VERSION");
698  
699 0 ▶ $self->resolve(sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
700 0 my $artifact = shift;
701 0 ▶ while (my($pkg, $data) = each %{$artifact->provides}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$artifact->provides;}) 0 0 0
702 0 my $package = Carton::Package->new($pkg, $data->{version}, $artifact->install->{pathname});
703 0 $index->add_package($package);
704 }
705 0 });
706  
707 0 $index;
708 }
709  
710 0 ▶sub requirements {
Subroutine requirements: not called CC=1 SCAR=6.9
Pod undocumented
711 0 my $self = shift;
712  
713 0 return $self->env->cpanfile->load->prereqs
714 ->merged_requirements(['runtime', 'test', 'develop'], ['requires']);
715 }
716  
717 1 1;
« Carmel/Builder.pm ↑ Summary Carmel/ProgressBar.pm »