lib/ASPEER/MakeMaker/MM/Util.pm

filter: Statementstmt 67.3% 165 / 245 Branchbran 26.1% 11 / 42 Conditioncond 17.0% 14 / 82 MC/DCmcdc 2.1% 1 / 46 Subroutinesub 71.4% 30 / 42 Podpod 75.0% 24 / 32 totaltotal 50.1% 245 / 489 CC 53 SCAR 18.7
CC
53
Cov
51%
perl_inc
18.1
perl_inc
18.1
perlrun
12.2
CRAP 6.5
« lib/ASPEER/MakeMaker/MM/Import.pm ↑ Summary lib/ASPEER/MakeMaker/MM/Constant.pm »
1 #
2 # This file is part of ASPEER::MakeMaker.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package ASPEER::MakeMaker::MM::Util;
14  
15  
16 # Pragma
17 #
18 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use vars qw($VERSION $DEBUG $QUIET $VERBOSE @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # External modules
24 #
25 3 ▶use FindBin qw($RealBin $Script);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 FindBin::again();
27 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 local $Data::Dumper::Indent=1;
31 3 local $Data::Dumper::Terse=1;
32 3 local $Data::Dumper::Sortkeys=1;
33  
34  
35 # Export functions
36 #
37 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 3 @EXPORT=qw(err msg verbose debug quiet_enable verbose_enable debug_enable Dumper slurp blurp touch arg perlrun);
39  
40  
41 # Version information in a format suitable for CPAN etc. Must be
42 # all on one line
43 #
44 3 $VERSION='1.012';
45  
46  
47 # Debugging on ?
48 #
49 3 $Script=~s/\.pl$//;
50 3 ▶($Carp::Verbose=++$DEBUG) if $ENV{uc("${Script}_DEBUG")};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{uc "$ASPEER::MakeMaker::MM::Util::Script_DEBUG"} 0 3 3
51  
52  
53 # Done
54 #
55 3 1;
56  
57 #==================================================================================================
58  
59  
60 0 ▶sub quiet_enable {
Subroutine quiet_enable: not called CC=2 SCAR=11.6
Pod documented
61  
62  
63 # Turn on quiet flag
64 #
65 1 ▶ $QUIET=shift() || 1;
Subroutine quiet_enable: called CC=2 SCAR=11.6
Pod documented
Condition0%0/4
shift() || 1
l!l
00
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/2
A
A= shift()
Aresult
11
00
66  
67  
68 }
69  
70  
71 0 ▶sub verbose {
Subroutine verbose: not called CC=3 SCAR=16.8
Pod documented
72  
73 # Print verbose message
74 #
75 1 ▶ return if $QUIET || !$VERBOSE;
Subroutine verbose: called CC=3 SCAR=16.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
if $ASPEER::MakeMaker::MM::Util::QUIET or not $ASPEER::MakeMaker::MM::Util::VERBOSE 0 0 0
if $ASPEER::MakeMaker::MM::Util::QUIET or not $ASPEER::MakeMaker::MM::Util::VERBOSE 0 1 1
Condition0%0/6
$ASPEER::MakeMaker::MM::Util::QUIET or not $ASPEER::MakeMaker::MM::Util::VERBOSE
l!l&&r!l&&!r
000
$ASPEER::MakeMaker::MM::Util::QUIET or not $ASPEER::MakeMaker::MM::Util::VERBOSE
l!l&&r!l&&!r
000
MC/DC0%0/2
$ASPEER::MakeMaker::MM::Util::QUIET or not $ASPEER::MakeMaker::MM::Util::VERBOSE
$ASPEER::MakeMaker::MM::Util::QUIET not $ASPEER::MakeMaker::MM::Util::VERBOSE
MC/DC0%0/2
$ASPEER::MakeMaker::MM::Util::QUIET or not $ASPEER::MakeMaker::MM::Util::VERBOSE
$ASPEER::MakeMaker::MM::Util::QUIET not $ASPEER::MakeMaker::MM::Util::VERBOSE
Truth table0%0/3
A or not(B)
A= $ASPEER::MakeMaker::MM::Util::QUIETB= not $ASPEER::MakeMaker::MM::Util::VERBOSE
ABresult
1X1
011
000
Truth table0%0/3
A or not(B)
A= $ASPEER::MakeMaker::MM::Util::QUIETB= not $ASPEER::MakeMaker::MM::Util::VERBOSE
ABresult
1X1
011
000
76 1 return CORE::print STDERR &fmt(@_), $/;
77  
78 }
79  
80  
81 0 ▶sub verbose_enable {
Subroutine verbose_enable: not called CC=2 SCAR=11.6
Pod documented
82  
83 # Turn on verbose flag
84 #
85 1 ▶ $VERBOSE=shift() || 1;
Subroutine verbose_enable: called CC=2 SCAR=11.6
Pod documented
Condition0%0/4
shift() || 1
l!l
00
shift() || 1
l!l
00
MC/DC0%0/1
shift() || 1
shift()
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
Truth table0%0/2
A
A= shift()
Aresult
11
00
86  
87 }
88  
89  
90 0 ▶sub debug_enable {
Subroutine debug_enable: not called CC=1 SCAR=0.0
Pod documented
91  
92 # Turn on debugging flag
93 #
94 1 ▶ $DEBUG=shift();
Subroutine debug_enable: called CC=1 SCAR=0.0
Pod documented
95  
96 }
97  
98  
99 0 ▶sub debug {
Subroutine debug: not called CC=2 SCAR=7.9
Pod documented
100  
101 # Debug
102 #
103 1 ▶ $DEBUG || return;
Subroutine debug: called CC=2 SCAR=7.9
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$ASPEER::MakeMaker::MM::Util::DEBUG or return 0 0 0
$ASPEER::MakeMaker::MM::Util::DEBUG or return 0 0 0
104 1 my $debug=sprintf(shift(), @_);
105 1 chomp($debug);
106 1 my ($package, undef, $line, $method) = caller(1); # '1' for caller of the function
107 print STDERR sprintf("[%s:%d] %s$/",
108 0 join('::', grep {$_} ($package, $method)),
109 $line,
110 $debug
111 );
112  
113 }
114  
115  
116 2 ▶sub err {
Subroutine err: called CC=1 SCAR=0.0
Pod documented
117  
118 # Quit on errors
119 #
120 1 ▶ my $msg=&fmt('error: %s', @_);
Subroutine err: called CC=1 SCAR=0.0
Pod documented
121 1 CORE::print STDERR $msg, "\n";
122 1 eval {require Carp; 1};
123 1 Carp::croak;
124  
125 }
126  
127  
128 23 ▶sub fmt {
Subroutine fmt: called CC=3 SCAR=11.7
Pod undocumented
129  
130  
131 # Format message nicely. Always called by err or msg so caller=2
132 #
133 1 ▶ my $message=sprintf(shift(), @_);
Subroutine fmt: called CC=3 SCAR=11.7
Pod undocumented
134 1 chomp($message);
135 1 my @caller=(caller(2));
136 1 ▶ my $caller=$caller[3] || $caller[0];
Condition16%1/6
$caller[3] || $caller[0]
l!l&&r!l&&!r
000
$caller[3] || $caller[0]
l!l&&r!l&&!r
2300
MC/DC0%0/2
$caller[3] || $caller[0]
$caller[3] $caller[0]
MC/DC0%0/2
$caller[3] || $caller[0]
$caller[3] $caller[0]
Truth table0%0/3
A || B
A= $caller[3]B= $caller[0]
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $caller[3]B= $caller[0]
ABresult
1X1
011
000
137 1 my ($class, $method)=($caller=~/^(.*)::([^:]+)$/);
138 1 ▶ $method ||=$caller[0];
Condition16%1/6
$method ||= $caller[0]
l!l&&r!l&&!r
000
$method ||= $caller[0]
l!l&&r!l&&!r
2300
MC/DC0%0/2
$method ||= $caller[0]
$method $caller[0]
MC/DC0%0/2
$method ||= $caller[0]
$method $caller[0]
Truth table0%0/3
A ||= B
A= $methodB= $caller[0]
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $methodB= $caller[0]
ABresult
1X1
011
000
139 1 $caller=~s/^_?!(_)//;
140 1 my $format=' @<<<<<<<<<<<<<<<<<< @*';
141 1 local $^A='';
142 1 formline $format, "[$method]", $message;
143 1 return $^A;
144  
145 }
146  
147  
148 21 ▶sub msg {
Subroutine msg: called CC=2 SCAR=9.2
Pod documented
149  
150 # Print message
151 #
152 1 ▶ return (CORE::print STDERR &fmt(@_), $/) unless $QUIET;
Subroutine msg: called CC=2 SCAR=9.2
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
unless $ASPEER::MakeMaker::MM::Util::QUIET 0 0 0
unless $ASPEER::MakeMaker::MM::Util::QUIET 21 0 21
153  
154 }
155  
156  
157 4 ▶sub slurp {
Subroutine slurp: called CC=3 SCAR=15.0
Pod documented
158  
159 # Slurp in file content
160 #
161 1 ▶ my ($fn)=@_;
Subroutine slurp: called CC=3 SCAR=15.0
Pod documented
162 0 ▶ my $fh=IO::File->new($fn, 'r') ||
Condition25%1/4
'IO::File'->new($fn, 'r') || (return err("unable to open file $fn, $!"))
l!l
00
'IO::File'->new($fn, 'r') || (return err("unable to open file $fn, $!"))
l!l
40
MC/DC0%0/1
'IO::File'->new($fn, 'r') || (return err("unable to open file $fn, $!"))
'IO::File'->new($fn, 'r')
MC/DC0%0/1
'IO::File'->new($fn, 'r') || (return err("unable to open file $fn, $!"))
'IO::File'->new($fn, 'r')
Truth table0%0/2
A
A= 'IO::File'->new($fn, 'r')
Aresult
11
00
Truth table50%1/2
A
A= 'IO::File'->new($fn, 'r')
Aresult
11
00
163 return err("unable to open file $fn, $!");
164 0 local $/=undef;
165 0 my $text=<$fh>;
166 0 $fh->close();
167 0 ▶ return $text || '';
Condition25%1/4
$text || ''
l!l
00
$text || ''
l!l
40
MC/DC0%0/1
$text || ''
$text
MC/DC0%0/1
$text || ''
$text
Truth table0%0/2
A
A= $text
Aresult
11
00
Truth table50%1/2
A
A= $text
Aresult
11
00
168  
169 }
170  
171  
172 4 ▶sub blurp {
Subroutine blurp: called CC=4 SCAR=18.9
Pod documented
173  
174 # Save file content
175 #
176 0 ▶ my ($fn, $text)=@_;
Subroutine blurp: called CC=4 SCAR=18.9
Pod documented
177 0 ▶ my $fh=IO::File->new($fn, 'w') ||
Condition25%1/4
'IO::File'->new($fn, 'w') || (return err("unable to open $fn for write, $!"))
l!l
00
'IO::File'->new($fn, 'w') || (return err("unable to open $fn for write, $!"))
l!l
40
MC/DC0%0/1
'IO::File'->new($fn, 'w') || (return err("unable to open $fn for write, $!"))
'IO::File'->new($fn, 'w')
MC/DC0%0/1
'IO::File'->new($fn, 'w') || (return err("unable to open $fn for write, $!"))
'IO::File'->new($fn, 'w')
Truth table0%0/2
A
A= 'IO::File'->new($fn, 'w')
Aresult
11
00
Truth table50%1/2
A
A= 'IO::File'->new($fn, 'w')
Aresult
11
00
178 return err("unable to open $fn for write, $!");
179 0 ▶ $fh->print($text) ||
Branch: 2 branches
BranchTrueFalseTotal
$fh->print($text) or return err("unable to write file $fn, $!") 0 0 0
$fh->print($text) or return err("unable to write file $fn, $!") 3 1 4
180 return err("unable to write file $fn, $!");
181 0 ▶ $fh->close() ||
Branch: 2 branches
BranchTrueFalseTotal
$fh->close or return err("unable to close file $fn, $!") 0 0 0
$fh->close or return err("unable to close file $fn, $!") 2 1 3
182 return err("unable to close file $fn, $!");
183 0 return 1;
184  
185 }
186  
187  
188 0 ▶sub touch {
Subroutine touch: not called CC=2 SCAR=17.9
Pod documented
189  
190 0 ▶ my ($fn)=@_;
Subroutine touch: not called CC=2 SCAR=17.9
Pod documented
191 0 ▶ return 1 if -e $fn;
Branch: 2 branches
BranchTrueFalseTotal
if -e $fn 0 0 0
if -e $fn 0 0 0
192 0 return blurp($fn, '');
193  
194 }
195  
196  
197 1 ▶sub perlrun {
Subroutine perlrun: called CC=6 SCAR=25.0
Pod documented
198  
199  
200 # Get self ref
201 #
202 0 ▶ my ($self, $mm_or)=@_;
Subroutine perlrun: not called CC=6 SCAR=25.0
Pod documented
203  
204  
205 # Construct PERL runtime
206 #
207 0 my $perl_inc_ar=&perl_inc;
208  
209  
210 # And modules
211 #
212 0 my $perl_mod_ar=&perl_mod;
213 0 my @import_class;
214 {
215 0 ▶ no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.1
216 0 @import_class=@MY::ExtUtils_MM_Import_Order;
217 }
218 0 ▶ @import_class=(ref($self)) unless @import_class;
Branch: 2 branches
BranchTrueFalseTotal
unless @import_class 0 0 0
unless @import_class 0 1 1
219 0 my %import_class=map {$_=>1} @import_class;
220 0 my @perl_mod_no_import=grep {!$import_class{$_}} @{$perl_mod_ar};
221 0 my %seen;
222 0 my @perl_mod=grep {!$seen{$_}++} (
223 @perl_mod_no_import,
224 @import_class
225 );
226  
227  
228 # Now construct final PERLRUN string
229 #
230 0 my $perlrun;
231 0 ▶ my $quote_cr=$mm_or && $mm_or->can('quote_literal');
Condition16%1/6
$mm_or && $mm_or->can('quote_literal')
!ll&&!rl&&r
000
$mm_or && $mm_or->can('quote_literal')
!ll&&!rl&&r
001
MC/DC0%0/2
$mm_or && $mm_or->can('quote_literal')
$mm_or $mm_or->can('quote_literal')
MC/DC0%0/2
$mm_or && $mm_or->can('quote_literal')
$mm_or $mm_or->can('quote_literal')
Truth table0%0/3
A && B
A= $mm_orB= $mm_or->can('quote_literal')
ABresult
0X0
100
111
Truth table33%1/3
A && B
A= $mm_orB= $mm_or->can('quote_literal')
ABresult
0X0
100
111
232 my $perlrun_inc=join(' ', map {
233 0 my $arg="-I$_";
234 0 ▶ $quote_cr ? $quote_cr->($mm_or, $arg) : $arg
Branch: 2 branches
BranchTrueFalseTotal
$quote_cr ? : 0 0 0
$quote_cr ? : 0 0 0
235 0 } @{$perl_inc_ar});
236 my $perlrun_mod=join(' ', map {
237 0 my $class=$_;
238 3 ▶ no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.0
239 0 my $import_tag_ar=$MY::ExtUtils_MM_Import_Tag{$class};
240 0 $import_tag_ar && @{$import_tag_ar} ?
241 0 ▶ sprintf('-M%s=%s', $class, join(',', @{$import_tag_ar})) :
Branch: 2 branches
BranchTrueFalseTotal
$import_tag_ar && @{$import_tag_ar;} ? : 0 0 0
$import_tag_ar && @{$import_tag_ar;} ? : 1 10 11
Condition33%2/6
$import_tag_ar and @{$import_tag_ar;}
!ll&&!rl&&r
000
$import_tag_ar and @{$import_tag_ar;}
!ll&&!rl&&r
1001
MC/DC0%0/2
$import_tag_ar and @{$import_tag_ar;}
$import_tag_ar @{$import_tag_ar;}
MC/DC50%1/2
$import_tag_ar and @{$import_tag_ar;}
$import_tag_ar @{$import_tag_ar;}
Truth table0%0/3
A and B
A= $import_tag_arB= @{$import_tag_ar;}
ABresult
0X0
100
111
Truth table66%2/3
A and B
A= $import_tag_arB= @{$import_tag_ar;}
ABresult
0X0
100
111
242 "-M$class"
243 } @perl_mod);
244 0 $perlrun="\$(PERL) $perlrun_inc $perlrun_mod";
245  
246  
247 # And return
248 #
249 0 return $perlrun
250  
251 }
252  
253  
254 1 ▶sub perl_mod {
Subroutine perl_mod: called CC=1 SCAR=1.2
Pod undocumented
255  
256 0 ▶ my %seen=(
Subroutine perl_mod: not called CC=1 SCAR=1.2
Pod undocumented
257 __PACKAGE__ => 1
258 );
259 my @m=sort
260 0 grep { !$seen{$_}++ }
261 0 map {(my $m = $_) =~ s{\.pm$}{}; $m =~ s{/}{::}g; $m;}
262 0 grep { m{^ExtUtils/} }
263 keys %INC;
264 0 return \@m;
265 }
266  
267  
268 1 ▶sub perl_inc {
Subroutine perl_inc: called CC=6 SCAR=29.0
Pod undocumented
269  
270 # Return array ref of any additional libraries specified via command line (-I)
271 #
272 0 ▶ my %default_inc=map { $_ => 1 } @{ perl_inc_default() || [] };
Subroutine perl_inc: not called CC=6 SCAR=29.0
Pod undocumented
Condition25%1/4
perl_inc_default() || []
l!l
00
perl_inc_default() || []
l!l
10
MC/DC0%0/1
perl_inc_default() || []
perl_inc_default()
MC/DC0%0/1
perl_inc_default() || []
perl_inc_default()
Truth table0%0/2
A
A= perl_inc_default()
Aresult
11
00
Truth table50%1/2
A
A= perl_inc_default()
Aresult
11
00
273 0 my %seen;
274 my @lib=grep {
275 0 ▶ !$default_inc{$_} && !$seen{$_}++
Condition16%1/6
$default_inc{$_} || $seen{$_}++
l!l&&r!l&&!r
000
$default_inc{$_} || $seen{$_}++
l!l&&r!l&&!r
700
MC/DC0%0/2
$default_inc{$_} || $seen{$_}++
$default_inc{$_} $seen{$_}++
MC/DC0%0/2
$default_inc{$_} || $seen{$_}++
$default_inc{$_} $seen{$_}++
Truth table0%0/3
A || B
A= $default_inc{$_}B= $seen{$_}++
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $default_inc{$_}B= $seen{$_}++
ABresult
1X1
011
000
276 } map {
277 0 File::Spec->rel2abs($_)
278 } grep {
279 0 ▶ defined($_) && !ref($_) && length($_) && -d $_
Condition16%3/18
defined $_ && !ref($_) && length $_ && -d $_
!ll&&!rl&&r
000
defined $_ and not ref $_ and length $_
!ll&&!rl&&r
000
defined $_ and not ref $_
!ll&&!rl&&r
000
defined $_ && !ref($_) && length $_ && -d $_
!ll&&!rl&&r
007
defined $_ and not ref $_ and length $_
!ll&&!rl&&r
007
defined $_ and not ref $_
!ll&&!rl&&r
007
MC/DC0%0/4
defined $_ && !ref($_) && length $_ && -d $_
defined $_ not ref $_ length $_ -d $_
MC/DC0%0/4
defined $_ && !ref($_) && length $_ && -d $_
defined $_ not ref $_ length $_ -d $_
Truth table0%0/5
A and not(B) and C && D
A= defined $_B= not ref $_C= length $_D= -d $_
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table20%1/5
A and not(B) and C && D
A= defined $_B= not ref $_C= length $_D= -d $_
ABCDresult
0XXX0
10XX0
110X0
11100
11111
280 } @INC;
281  
282 0 return \@lib;
283 }
284  
285  
286 1 ▶sub perl_inc_default {
Subroutine perl_inc_default: called CC=3 SCAR=15.7
Pod undocumented
287  
288 0 ▶ my @default_inc;
Subroutine perl_inc_default: not called CC=3 SCAR=15.7
Pod undocumented
289 0 ▶ if (open(my $perl_fh, '-|', $^X, '-e', 'print join qq(\0), grep { defined && !ref && length && -d } @INC')) {
Branch: 2 branches
BranchTrueFalseTotal
if (open my $perl_fh, "-|", $^X, "-e", "print join qq(\\0), grep { defined && !ref && length && -d } \@INC") 0 0 0
if (open my $perl_fh, "-|", $^X, "-e", "print join qq(\\0), grep { defined && !ref && length && -d } \@INC") 1 0 1
290 0 local $/;
291 0 my $inc=<$perl_fh>;
292 0 close($perl_fh);
293 @default_inc=map {
294 0 ▶ File::Spec->rel2abs($_)
Condition25%1/4
$inc || ''
l!l
00
$inc || ''
l!l
10
MC/DC0%0/1
$inc || ''
$inc
MC/DC0%0/1
$inc || ''
$inc
Truth table0%0/2
A
A= $inc
Aresult
11
00
Truth table50%1/2
A
A= $inc
Aresult
11
00
295 } split(/\0/, ($inc || ''));
296 }
297 0 return \@default_inc;
298 }
299  
300  
301 3 ▶sub arg {
Subroutine arg: called CC=1 SCAR=1.2
Pod documented
302  
303 # Convert MakeMaker target args to a named parameter hash.
304 #
305 0 ▶ my (%param, @argv);
Subroutine arg: not called CC=1 SCAR=1.2
Pod documented
306 0 (@param{qw(
307 NAME
308 NAME_SYM
309 DISTNAME
310 DISTVNAME
311 VERSION
312 VERSION_SYM
313 VERSION_FROM
314 LICENSE AUTHOR
315 TO_INST_PM
316 EXE_FILES
317 DIST_DEFAULT_TARGET
318 SUFFIX
319 ABSTRACT_FROM
320 )}, @argv)=@_;
321 0 $param{'TO_INST_PM_AR'}=[split /\s+/, $param{'TO_INST_PM'}];
322 0 $param{'EXE_FILES_AR'}=[split /\s+/, $param{'EXE_FILES'}];
323 0 $param{'ARGV_AR'}=\@argv;
324 0 return \%param
325  
326 }
327  
328 __END__
« lib/ASPEER/MakeMaker/MM/Import.pm ↑ Summary lib/ASPEER/MakeMaker/MM/Constant.pm »