blib/lib/App/eachperl.pm

filter: Statementstmt 37.0% 119 / 321 Branchbran 0.0% 0 / 88 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 50.0% 25 / 50 Podpod 0.0% 0 / 17 totaltotal 26.6% 144 / 541 CC 64 SCAR 44.0
CC
64
Cov
27%
exec
272.0
perls
182.0
postprocess_config
90.0
CRAP 81.8
↑ Summary
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2020-2024 -- leonerd@leonerd.org.uk
5  
6 1 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Object::Pad 0.800;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package App::eachperl 0.11;
11 class App::eachperl;
12  
13 1 ▶use Object::Pad::FieldAttr::Checked 0.04;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Data::Checks 0.08 qw( Str Maybe );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use Config::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Syntax::Keyword::Dynamically;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use Commandable::Finder::MethodAttributes 0.13 ':attrs';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Commandable::Invocation;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use IO::Term::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use IPC::Run ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use String::Tagged 0.17;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Convert::Color::XTerm 0.06;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 my $RESET = "\e[m";
28 1 my $BOLD = "\e[1m";
29  
30 my %COL = (
31 1 ( map { $_ => Convert::Color->new( "vga:$_" ) } qw( red blue green ) ),
32 grey => Convert::Color->new( "xterm:grey(70%)" ),
33 );
34  
35 # Allow conversion of signal numbers into names
36 1 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 my @SIGNAMES = split m/\s+/, $Config{sig_name};
38  
39 =head1 NAME
40  
41 C<App::eachperl> - a wrapper script for iterating multiple F<perl> binaries
42  
43 =head1 SYNOPSIS
44  
45 $ eachperl exec -E 'say "Hello"'
46  
47 --- perl5.30.0 ---
48 Hello
49  
50 --- bleadperl ---
51 Hello
52  
53 ----------
54 perl5.30.0 : 0
55 bleadperl : 0
56  
57 =head1 DESCRIPTION
58  
59 For more detail see the manpage for the eachperl(1) script.
60  
61 =cut
62  
63 1 my $VersionString_re;
64 my $VersionString;
65 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
66 1 $VersionString = Data::Checks::StrMatch
67 $VersionString_re = qr/^v?\d+(?:\.\d+)*$/;
68 }
69  
70 1 field $_finder;
71  
72 1 field $_perls;
73 field $_install_no_system :param = undef;
74 1 field $_no_system_perl = !!$ENV{NO_SYSTEM_PERL};
75 1 field $_no_test;
76 1 field $_since_version;
77 1 field $_until_version;
78 1 field $_use_devel;
79 1 field $_only_if;
80 1 field $_reverse;
81 1 field $_stop_on_fail;
82  
83 field $_io_term = IO::Term::Status->new_for_stdout;
84  
85 1 class App::eachperl::_Perl {
86 0 ▶ field $name :param :reader :Checked(Str);
Subroutine name: not called CC=1 SCAR=2.6
87 0 ▶ field $fullpath :param :reader :Checked(Str);
Subroutine fullpath: not called CC=1 SCAR=2.6
88 0 ▶ field $version :param :reader :Checked($VersionString);
Subroutine version: not called CC=1 SCAR=2.6
89 0 ▶ field $is_threads :param :reader;
Subroutine is_threads: not called CC=1 SCAR=2.6
90 0 ▶ field $is_debugging :param :reader;
Subroutine is_debugging: not called CC=1 SCAR=2.6
91 0 ▶ field $is_devel :param :reader;
Subroutine is_devel: not called CC=1 SCAR=2.6
92 0 ▶ field $selected :mutator;
Subroutine selected: not called CC=1 SCAR=2.6
93 }
94  
95 1 field @_perlobjs;
96  
97 ADJUST
98 {
99 $_finder = Commandable::Finder::MethodAttributes->new( object => $self );
100  
101 $_finder->add_global_options(
102 { name => "no-system-perl", into => \$_no_system_perl,
103 description => "Deselects the system perl version" },
104 { name => "no-test", into => \$_no_test,
105 description => "Skips the 'test' step when building a local distribution" },
106 { name => "since=", into => \$_since_version,
107 matches => $VersionString_re, match_msg => "a version string",
108 description => "Selects only perl versions that are at least as new as the requested version" },
109 { name => "until=", into => \$_until_version,
110 matches => $VersionString_re, match_msg => "a version string",
111 description => "Selects only perl versions that are at least as old as the requested version" },
112 { name => "version|v=", into => sub { $_since_version = $_until_version = $_[1] },
113 matches => $VersionString_re, match_msg => "a version string",
114 description => "Selects only the given perl version" },
115 { name => "devel", into => \$_use_devel, mode => "bool",
116 description => "Select only perl versions that are (or are not) development versions" },
117 { name => "only-if=", into => \$_only_if,
118 description => "Select only perl versions where this expression returns true" },
119 { name => "reverse|r", into => \$_reverse,
120 description => "Reverses the order in which perl versions are invoked" },
121 { name => "stop-on-fail|s", into => \$_stop_on_fail,
122 description => "Stops running after the first failure" },
123 );
124  
125 $self->maybe_apply_config( "./.eachperlrc" );
126 $self->maybe_apply_config( "$ENV{HOME}/.eachperlrc" );
127 }
128  
129 0 ▶method maybe_apply_config ( $path )
Subroutine maybe_apply_config: not called CC=8 SCAR=41.9
Pod undocumented
130 {
131 # Only accept files readable and owned by UID
132 0 ▶ return unless -r $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $path 0 0 0
133 0 ▶ return unless -o _;
Branch: 1 branch
BranchTrueFalseTotal
unless -O _ 0 0 0
134  
135 0 my $config = Config::Tiny->read( $path );
136  
137 0 ▶ $_perls //= $config->{_}{perls};
Condition0%0/3
$_perls //= $config->{"_"}{"perls"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_perls //= $config->{"_"}{"perls"}
$_perls $config->{"_"}{"perls"}
Truth table0%0/3
A //= B
A= $_perlsB= $config->{"_"}{"perls"}
ABresult
1X1
011
000
138 0 ▶ $_since_version //= $config->{_}{since_version};
Condition0%0/3
$_since_version //= $config->{"_"}{"since_version"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_since_version //= $config->{"_"}{"since_version"}
$_since_version $config->{"_"}{"since_version"}
Truth table0%0/3
A //= B
A= $_since_versionB= $config->{"_"}{"since_version"}
ABresult
1X1
011
000
139 0 ▶ $_until_version //= $config->{_}{until_version};
Condition0%0/3
$_until_version //= $config->{"_"}{"until_version"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_until_version //= $config->{"_"}{"until_version"}
$_until_version $config->{"_"}{"until_version"}
Truth table0%0/3
A //= B
A= $_until_versionB= $config->{"_"}{"until_version"}
ABresult
1X1
011
000
140 0 ▶ $_only_if //= $config->{_}{only_if};
Condition0%0/3
$_only_if //= $config->{"_"}{"only_if"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_only_if //= $config->{"_"}{"only_if"}
$_only_if $config->{"_"}{"only_if"}
Truth table0%0/3
A //= B
A= $_only_ifB= $config->{"_"}{"only_if"}
ABresult
1X1
011
000
141 0 ▶ $_install_no_system //= $config->{_}{install_no_system};
Condition0%0/3
$_install_no_system //= $config->{"_"}{"install_no_system"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_install_no_system //= $config->{"_"}{"install_no_system"}
$_install_no_system $config->{"_"}{"install_no_system"}
Truth table0%0/3
A //= B
A= $_install_no_systemB= $config->{"_"}{"install_no_system"}
ABresult
1X1
011
000
142 1 }
143  
144 0 ▶method postprocess_config ()
Subroutine postprocess_config: not called CC=9 SCAR=45.0
Pod undocumented
145 {
146 0 foreach ( $_since_version, $_until_version ) {
147 0 ▶ defined $_ or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or next 0 0 0
148 0 ▶ m/^v/ or $_ = "v$_";
Branch: 1 branch
BranchTrueFalseTotal
/^v/u or $_ = "v$_" 0 0 0
149 # E.g. --until 5.14 means until the /end/ of the 5.14 series; so 5.14.999
150 0 ▶ $_ .= ".999" if \$_ == \$_until_version and $_ !~ m/\.\d+\./;
Branch: 1 branch
BranchTrueFalseTotal
if \$_ == \$_until_version and not $_ =~ /\.\d+\./u 0 0 0
Condition0%0/3
\$_ == \$_until_version and not $_ =~ /\.\d+\./u
!ll&&!rl&&r
000
MC/DC0%0/2
\$_ == \$_until_version and not $_ =~ /\.\d+\./u
\$_ == \$_until_version not $_ =~ /\.\d+\./u
Truth table0%0/3
A and not(B)
A= \$_ == \$_until_versionB= not $_ =~ /\.\d+\./u
ABresult
0X0
100
111
151 0 $_ = version->parse( $_ )->stringify;
152 }
153  
154 0 ▶ if( my $perlnames = $_perls ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $perlnames = $_perls) 0 0 0
155 0 foreach my $perl ( split m/\s+/, $perlnames ) {
156 0 chomp( my $fullpath = `which $perl` );
157 0 ▶ $? and warn( "Can't find perl at $perl" ), next;
Branch: 1 branch
BranchTrueFalseTotal
$? and warn("Can't find perl at $perl"), next 0 0 0
158  
159 0 my ( $ver, $usethreads, $ccflags ) = split m/\n/,
160 scalar `$fullpath -MConfig -e 'print "\$]\\n\$Config{usethreads}\\n\$Config{ccflags}\\n"'`;
161  
162 0 $ver = version->parse( $ver )->normal;
163 0 my $threads = ( $usethreads eq "define" );
164 0 my $debug = $ccflags =~ m/-DDEBUGGING\b/;
165 0 my $devel = ( $ver =~ m/^v\d+\.(\d+)/ )[0] % 2;
166  
167 0 push @_perlobjs, App::eachperl::_Perl->new(
168 name => $perl,
169 fullpath => $fullpath,
170 version => $ver,
171 is_threads => $threads,
172 is_debugging => $debug,
173 is_devel => $devel,
174 );
175 }
176 }
177 1 }
178  
179 0 ▶method perls ()
Subroutine perls: not called CC=13 SCAR=52.0
Pod undocumented
180 {
181 0 my @perls = @_perlobjs;
182 0 ▶ @perls = reverse @perls if $_reverse;
Branch: 1 branch
BranchTrueFalseTotal
if $_reverse 0 0 0
183  
184 return map {
185 0 my $perl = $_;
186 0 my $ver = $perl->version;
187  
188 0 my $selected = 1;
189 0 ▶ $selected = 0 if $_since_version and $ver lt $_since_version;
Branch: 1 branch
BranchTrueFalseTotal
if $_since_version and $ver lt $_since_version 0 0 0
Condition0%0/3
$_since_version and $ver lt $_since_version
!ll&&!rl&&r
000
MC/DC0%0/2
$_since_version and $ver lt $_since_version
$_since_version $ver lt $_since_version
Truth table0%0/3
A and B
A= $_since_versionB= $ver lt $_since_version
ABresult
0X0
100
111
190 0 ▶ $selected = 0 if $_until_version and $ver gt $_until_version;
Branch: 1 branch
BranchTrueFalseTotal
if $_until_version and $ver gt $_until_version 0 0 0
Condition0%0/3
$_until_version and $ver gt $_until_version
!ll&&!rl&&r
000
MC/DC0%0/2
$_until_version and $ver gt $_until_version
$_until_version $ver gt $_until_version
Truth table0%0/3
A and B
A= $_until_versionB= $ver gt $_until_version
ABresult
0X0
100
111
191 0 ▶ $selected = 0 if $_no_system_perl and $perl->fullpath eq $^X;
Branch: 1 branch
BranchTrueFalseTotal
if $_no_system_perl and $perl->fullpath eq $^X 0 0 0
Condition0%0/3
$_no_system_perl and $perl->fullpath eq $^X
!ll&&!rl&&r
000
MC/DC0%0/2
$_no_system_perl and $perl->fullpath eq $^X
$_no_system_perl $perl->fullpath eq $^X
Truth table0%0/3
A and B
A= $_no_system_perlB= $perl->fullpath eq $^X
ABresult
0X0
100
111
192 0 ▶ $selected = 0 if defined $_use_devel and $perl->is_devel ^ $_use_devel;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_use_devel and $perl->is_devel ^ $_use_devel 0 0 0
Condition0%0/3
defined $_use_devel and $perl->is_devel ^ $_use_devel
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_use_devel and $perl->is_devel ^ $_use_devel
defined $_use_devel $perl->is_devel ^ $_use_devel
Truth table0%0/3
A and B
A= defined $_use_develB= $perl->is_devel ^ $_use_devel
ABresult
0X0
100
111
193  
194 0 ▶ if( $selected and defined $_only_if ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($selected and defined $_only_if) 0 0 0
Condition0%0/3
$selected and defined $_only_if
!ll&&!rl&&r
000
MC/DC0%0/2
$selected and defined $_only_if
$selected defined $_only_if
Truth table0%0/3
A and B
A= $selectedB= defined $_only_if
ABresult
0X0
100
111
195 0 ▶ IPC::Run::run(
Branch: 1 branch
BranchTrueFalseTotal
IPC::Run::run([$perl->fullpath, "-Mstrict", "-Mwarnings", "-MConfig", "-e", "exit !do {$_only_if}"]) == 0 and $selected = 0 0 0 0
196 [ $perl->fullpath, "-Mstrict", "-Mwarnings", "-MConfig",
197 "-e", "exit !do {$_only_if}" ]
198 ) == 0 and $selected = 0;
199 }
200  
201 0 $perl->selected = $selected;
202  
203 0 $perl;
204 } @perls;
205 1 }
206  
207 0 ▶method run ( @argv )
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
208 {
209 0 my $cinv = Commandable::Invocation->new_from_tokens( @argv );
210  
211 0 $_finder->handle_global_options( $cinv );
212  
213 0 $self->postprocess_config;
214  
215 0 ▶ if( $cinv->peek_remaining =~ m/^-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cinv->peek_remaining =~ /^-/u) 0 0 0
216 0 $cinv->putback_tokens( "exec" );
217 }
218  
219 0 return $_finder->find_and_invoke( $cinv );
220 1 }
221  
222 method command_list
223 0 ▶ :Command_description("List the available perls")
Subroutine command_list: not called CC=6 SCAR=37.4
Pod undocumented
224 0 ()
225 {
226 0 foreach my $perl ( $self->perls ) {
227 0 my @flags;
228 0 push @flags, $perl->version;
229 0 ▶ push @flags, "threads" if $perl->is_threads;
Branch: 1 branch
BranchTrueFalseTotal
if $perl->is_threads 0 0 0
230 0 ▶ push @flags, "DEBUGGING" if $perl->is_debugging;
Branch: 1 branch
BranchTrueFalseTotal
if $perl->is_debugging 0 0 0
231 0 ▶ push @flags, "devel" if $perl->is_devel;
Branch: 1 branch
BranchTrueFalseTotal
if $perl->is_devel 0 0 0
232  
233 0 ▶ printf "%s%s: %s (%s)\n",
Branch: 1 branch
BranchTrueFalseTotal
$perl->selected ? : 0 0 0
234 ( $perl->selected ? "* " : " " ),
235 $perl->name, $perl->fullpath, join( ",", @flags ),
236 ;
237 }
238 0 return 0;
239 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
240  
241 0 ▶method exec ( @argv )
Subroutine exec: not called CC=16 SCAR=56.1
Pod undocumented
242 {
243 0 ▶ my %opts = %{ shift @argv } if @argv and ref $argv[0] eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if @argv and ref $argv[0] eq "HASH" 0 0 0
Condition0%0/3
@argv and ref $argv[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@argv and ref $argv[0] eq "HASH"
@argv ref $argv[0] eq "HASH"
Truth table0%0/3
A and B
A= @argvB= ref $argv[0] eq "HASH"
ABresult
0X0
100
111
244  
245 0 my @results;
246 0 my $ok = 1;
247  
248 0 my $signal;
249  
250 0 my @perls = $self->perls;
251 0 my $idx = 0;
252 0 foreach ( @perls ) {
253 0 $idx++;
254 0 ▶ next unless $_->selected;
Branch: 1 branch
BranchTrueFalseTotal
unless $_->selected 0 0 0
255  
256 0 my $perl = $_->name;
257 0 my $path = $_->fullpath;
258  
259 my @status = (
260 ( $ok
261 ? String::Tagged->new_tagged( "-OK-", fg => $COL{grey} )
262 : String::Tagged->new_tagged( "FAIL", fg => $COL{red} ) ),
263  
264 String::Tagged->new
265 ->append( "Running " )
266 ->append_tagged( $perl, bold => 1 ),
267  
268 ( $idx < @perls
269 ? String::Tagged->new_tagged( sprintf( "(%d more)", @perls - $idx ), fg => $COL{grey} )
270 0 ▶ : () ),
Branch: 2 branches
BranchTrueFalseTotal
$ok ? : 0 0 0
$idx < @perls ? : 0 0 0
271 );
272  
273 0 $_io_term->set_status(
274 String::Tagged->join( " | ", @status )
275 ->apply_tag( 0, -1, bg => Convert::Color->new( "vga:blue" ) )
276 );
277  
278 $opts{oneline}
279 0 ▶ ? $_io_term->more_partial( "$BOLD$perl:$RESET " )
Branch: 1 branch
BranchTrueFalseTotal
$opts{'oneline'} ? : 0 0 0
280 : $_io_term->print_line( "\n$BOLD --- $perl --- $RESET" );
281  
282 0 my $has_partial = $opts{oneline};
283 0 ▶ IPC::Run::run [ $path, @argv ], ">pty>", sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
284 0 my @lines = split m/\r?\n/, $_[0], -1;
285  
286 0 ▶ if( $has_partial ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_partial) 0 0 0
287 0 my $line = shift @lines;
288  
289 0 ▶ if( $line =~ s/^\r// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ s/^\r//u) { } 0 0 0
290 0 $_io_term->replace_partial( $line );
291 }
292 else {
293 0 $_io_term->more_partial( $line );
294 }
295  
296 0 ▶ if( @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 0 0 0
297 0 $_io_term->finish_partial;
298 0 $has_partial = 0;
299 }
300 }
301  
302 # Final element will be empty string if it ended in a newline
303 0 my $partial = pop @lines;
304  
305 0 $_io_term->print_line( $_ ) for @lines;
306  
307 0 ▶ if( length $partial ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $partial) 0 0 0
308 0 $_io_term->more_partial( $partial );
309 0 $has_partial = 1;
310 }
311 0 };
312  
313 0 ▶ if( $has_partial ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_partial) 0 0 0
314 0 $_io_term->finish_partial;
315 }
316  
317 0 ▶ if( $? & 127 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? & 127) { } 0 0 0
318 # Exited via signal
319 0 $signal = $?;
320 0 push @results, [ $perl => "aborted on SIG$SIGNAMES[ $? ]" ];
321 0 last;
322 }
323 else {
324 0 push @results, [ $perl => $? >> 8 ];
325 0 ▶ last if $? and $_stop_on_fail;
Branch: 1 branch
BranchTrueFalseTotal
if $? and $_stop_on_fail 0 0 0
Condition0%0/3
$? and $_stop_on_fail
!ll&&!rl&&r
000
MC/DC0%0/2
$? and $_stop_on_fail
$? $_stop_on_fail
Truth table0%0/3
A and B
A= $?B= $_stop_on_fail
ABresult
0X0
100
111
326 }
327  
328 0 ▶ $ok = 0 if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
329 }
330  
331 0 $_io_term->set_status( "" );
332  
333 0 ▶ unless( $opts{no_summary} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"no_summary"}) 0 0 0
334 0 $_io_term->print_line( "\n----------" );
335 0 $_io_term->print_line( sprintf "%-20s: %s", @$_ ) for @results;
336 }
337  
338 0 ▶ kill $signal, $$ if $signal;
Branch: 1 branch
BranchTrueFalseTotal
if $signal 0 0 0
339 0 return 0;
340 1 }
341  
342 method command_exec
343 0 ▶ :Command_description("Execute a given command on each selected perl")
Subroutine command_exec: not called CC=1 SCAR=6.9
Pod undocumented
344 :Command_arg("argv...", "commandline arguments")
345 0 ( $argv )
346 {
347 0 return $self->exec( @$argv );
348 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
349  
350 0 ▶method cpan ( $e, @argv )
Subroutine cpan: not called CC=1 SCAR=6.9
Pod undocumented
351 {
352 0 return $self->exec( "-MCPAN", "-e", $e, @argv );
353 1 }
354  
355 0 ▶method invoke_local ( %opts )
Subroutine invoke_local: not called CC=8 SCAR=42.8
Pod undocumented
356 {
357 0 my $perl = "";
358 0 my @args;
359  
360 0 ▶ if( -r "Build.PL" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-r 'Build.PL') { } 0 0 0
elsif (-r 'Makefile.PL') { } 0 0 0
361 0 $perl .= <<'EOPERL';
362 system( $^X, "Build.PL" ) == 0 and
363 system( $^X, "Build", "clean" ) == 0 and
364 system( $^X, "Build" ) == 0
365 EOPERL
366 0 ▶ $perl .= ' and system( $^X, "Build", "test" ) == 0' if $opts{test};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"test"} 0 0 0
367 0 ▶ $perl .= ' and system( $^X, "Build", "install" ) == 0' if $opts{install};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"install"} 0 0 0
368 }
369 elsif( -r "Makefile.PL" ) {
370 0 $perl .= <<'EOPERL';
371 system( $^X, "Makefile.PL" ) == 0 and
372 system( "make" ) == 0
373 EOPERL
374 0 ▶ $perl .= ' and system( "make", "test" ) == 0' if $opts{test};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"test"} 0 0 0
375 0 ▶ $perl .= ' and system( "make", "install" ) == 0' if $opts{install};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"install"} 0 0 0
376 }
377 else {
378 0 die "TODO: Work out how to locally control dist when lacking Build.PL or Makefile.PL";
379 }
380  
381 0 ▶ $perl .= ' and system( $^X, @ARGV ) == 0', push @args, "--", @{$opts{perl}} if $opts{perl};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"perl"} 0 0 0
382  
383 0 return $self->exec( "-e", $perl . <<'EOPERL', @args);
384 and print "-- PASS -\n" or print "-- FAIL --\n";
385 kill $?, $$ if $? & 127;
386 exit +($? >> 8);
387 EOPERL
388 1 }
389  
390 method command_install
391 0 ▶ :Command_description("Installs a given module")
Subroutine command_install: not called CC=3 SCAR=24.8
Pod undocumented
392 :Command_arg("module", "name of the module (or \".\" for current directory)")
393 0 ( $module )
394 {
395 0 ▶ dynamically $_no_system_perl = 1 if $_install_no_system;
Branch: 1 branch
BranchTrueFalseTotal
if $_install_no_system 0 0 0
396  
397 0 ▶ return $self->command_install_local if $module eq ".";
Branch: 1 branch
BranchTrueFalseTotal
if $module eq "." 0 0 0
398 0 return $self->cpan( 'CPAN::Shell->install($ARGV[0])', $module );
399 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
400  
401 method command_install_local
402 0 ▶ :Command_description("Installs a module from the current directory")
Subroutine command_install_local: not called CC=1 SCAR=6.9
Pod undocumented
403 0 ()
404 {
405 0 $self->invoke_local( test => !$_no_test, install => 1 );
406 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
407  
408 method command_test
409 0 ▶ :Command_description("Tests a given module")
Subroutine command_test: not called CC=2 SCAR=17.9
Pod undocumented
410 :Command_arg("module", "name of the module (or \".\" for current directory)")
411 0 ( $module )
412 {
413 0 ▶ return $self->command_test_local if $module eq ".";
Branch: 1 branch
BranchTrueFalseTotal
if $module eq "." 0 0 0
414 0 return $self->cpan( 'CPAN::Shell->test($ARGV[0])', $module );
415 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
416  
417 method command_test_local
418 0 ▶ :Command_description("Tests a module from the current directory")
Subroutine command_test_local: not called CC=1 SCAR=6.9
Pod undocumented
419 0 ()
420 {
421 0 $self->invoke_local( test => 1 );
422 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
423  
424 method command_build_then_perl
425 0 ▶ :Command_description("Build the module in the current directory then run a perl command")
Subroutine command_build_then_perl: not called CC=1 SCAR=6.9
Pod undocumented
426 :Command_arg("argv...", "commandline arguments")
427 0 ( $argv )
428 {
429 0 $self->invoke_local( test => !$_no_test, perl => [ @$argv ] );
430 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
431  
432 method command_modversion
433 0 ▶ :Command_description("Print the installed module version")
Subroutine command_modversion: not called CC=1 SCAR=6.9
Pod undocumented
434 :Command_arg("module", "name of the module")
435 0 ( $module )
436 {
437 0 return $self->exec(
438 { oneline => 1, no_summary => 1 },
439 "-M$module", "-e", "print ${module}\->VERSION, qq(\\n);"
440 );
441 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
442  
443 method command_modpath
444 0 ▶ :Command_description("Print the installed module path")
Subroutine command_modpath: not called CC=1 SCAR=6.9
Pod undocumented
445 :Command_arg("module", "name of the module")
446 0 ( $module )
447 {
448 0 ( my $filename = "$module.pm" ) =~ s{::}{/}g;
449  
450 0 return $self->exec(
451 { oneline => 1, no_summary => 1 },
452 "-M$module", "-e", "print \$INC{qq($filename)}, qq(\\n);"
453 );
454 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
455  
456 method command_uninstall
457 0 ▶ :Command_description("Uninstalls a module")
Subroutine command_uninstall: not called CC=1 SCAR=6.9
Pod undocumented
458 :Command_arg("module", "name of the module")
459 0 ( $module )
460 {
461 0 return $self->exec(
462 "-e", <<'EOPERL' =~ s/^\s+//gr, $module
463 use Errno;
464 my $module = shift;
465 ( my $path = $module ) =~ s{::}{/}g;
466 my $packlist;
467 foreach ( @INC ) {
468 my $trial = "$_/auto/$path/.packlist";
469 next unless -f $trial;
470 $packlist = $trial; last;
471 }
472 defined $packlist or
473 die "Unable to find a .packlist file for $module\n";
474 open my $fh, "<", $packlist or
475 die "Unable to read $packlist - $!";
476 my $failed;
477 sub remove {
478 my ( $path ) = @_;
479 unlink $path or
480 $! == Errno::ENOENT or
481 $failed++, warn("Unable to unlink $path - $!"), return;
482 print "UNLINK $path\n";
483  
484 while( length $path ) {
485 $path =~ s{/[^/]+$}{};
486 rmdir $path and next;
487 $! == Errno::ENOENT and next;
488 $! == Errno::ENOTEMPTY and last;
489  
490 $failed++, warn("Unable to rmdir $path - $!"), return;
491 }
492 }
493 while( <$fh> ) {
494 chomp;
495 remove($_);
496 }
497 remove($packlist) if !$failed;
498 exit $failed;
499 EOPERL
500 );
501 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
502  
503 =head1 AUTHOR
504  
505 Paul Evans <leonerd@leonerd.org.uk>
506  
507 =cut
508  
509 1 0x55AA;
↑ Summary