blib/lib/ASPEER/MakeMaker/MM/Import.pm

filter: Statementstmt 26.3% 44 / 167 Branchbran 4.3% 2 / 46 Conditioncond 0.0% 0 / 49 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 60.8% 14 / 23 Podpod 66.6% 4 / 6 totaltotal 20.0% 64 / 320 CC 43 SCAR 45.8
CC
43
Cov
18%
post_initialize
210.0
const_config
156.0
import
98.9
CRAP 97.1
↑ Summary blib/lib/ASPEER/MakeMaker.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::Import;
14  
15  
16 # Pragma
17 #
18 1 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Base Packages
24 #
25 1 ▶use ASPEER::MakeMaker::MM;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use ASPEER::MakeMaker::MM::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use ASPEER::MakeMaker::MM::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30 # External Packages
31 #
32 1 ▶use ExtUtils::MakeMaker;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Software::LicenseUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use File::Basename qw(basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use Tie::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37  
38 # Version information in a formate suitable for CPAN etc. Must be
39 # all on one line
40 #
41 1 $VERSION='1.011';
42  
43  
44 # All done, init finished
45 #
46 1 1;
47  
48  
49 #======================================================================================================================
50  
51  
52 1 ▶sub import {
Subroutine import: called CC=12 SCAR=45.9
53  
54  
55 # Manage activation of various ExtUtils::Makemaker sections for this class.
56 #
57 # use ExtUtils::<This Package> qw(const_config) to just replace the macros section of the Makefile
58 # .. qw(dist_ci) to replace standard MakeMaker targets with our own
59 # .. qw(:all) or no tag (i.e defaults) to all targers
60 #
61 #
62 1 my ($class, @section)=@_;
63 1 ▶ return if $_{$class}{'loaded'}++;
Branch: 1 branch
BranchTrueFalseTotal
if $_{$class}{"loaded"}++ 0 1 1
64 1 ▶ return unless ($0=~/Makefile\.PL$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $0 =~ /Makefile\.PL$/ 1 0 1
65 0 msg("initializing $class import");
66  
67  
68 # Remember extension activation order for generated PERLRUN commands
69 #
70 {
71 1 ▶ no warnings qw(once);
Subroutine BEGIN: called CC=1 SCAR=0.2
72 push(@MY::ExtUtils_MM_Import_Order, $class)
73 0 ▶ unless grep {$class eq $_} @MY::ExtUtils_MM_Import_Order;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$class eq $_;} @MY::ExtUtils_MM_Import_Order 0 0 0
74 0 $MY::ExtUtils_MM_Import_Tag{$class}=[@section];
75 }
76  
77  
78 # Get params, bless self ref and remember import tags spec'd for later
79 # re-use
80 #
81 0 my $self=bless (\my %self, $class);
82  
83  
84 # Build chain of MM modules loaded for this OS so we can search for
85 # code ref's associated with various ExtUtils::MakeMaker sections;
86 #
87 0 my @mm_isa=grep {/^ExtUtils::MM/} @ExtUtils::MM::ISA;
88 0 push @mm_isa, map { @{"${_}::ISA"} } @mm_isa;
89 0 ▶ die('no ExtUtils::MM inheritance found in @ISA') unless @mm_isa;
Branch: 1 branch
BranchTrueFalseTotal
unless @mm_isa 0 0 0
90  
91  
92 # Sections to augment with additional targets
93 #
94 1 ▶ { no warnings qw(redefine once);
Subroutine BEGIN: called CC=1 SCAR=0.2
95 0 foreach my $section (qw(const_config depend postamble post_initialize), @section) {
96 0 ▶ next if $self{$section};
Branch: 1 branch
BranchTrueFalseTotal
if $self{$section} 0 0 0
97 0 $self{$section} =*{"ExtUtils::MM::${section}"}{CODE}; # unless (*{"ExtUtils::MM::${section}"}{CODE} eq \&{$section});
98 0 ▶ $self{$section} ||= do {
Condition0%0/3
$self{$section} ||= do { my($cr) = grep({$_;} map({$_->can($section);} @mm_isa)); $cr or sub { ""; } }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self{$section} ||= do { my($cr) = grep({$_;} map({$_->can($section);} @mm_isa)); $cr or sub { ""; } }
$self{$section} do { my($cr) = grep({$_;} map({$_->can($section);} @mm_isa)); $cr or sub { ""; } }
Truth table0%0/3
A ||= B
A= $self{$section}B= do { my($cr) = grep({$_;} map({$_->can($section);} @mm_isa)); $cr or sub { ""; } }
ABresult
1X1
011
000
99 0 my ($cr)=grep {$_} (map { $_->can($section) } @mm_isa);
100 0 ▶ $cr || sub {''};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$cr || sub { ''; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$cr || sub { ''; }
$cr sub { ''; }
Truth table0%0/3
A || B
A= $crB= sub { ''; }
ABresult
1X1
011
000
101 };
102 0 ▶ $self{$section} ||= ExtUtils::MM_Unix->can($section) || sub {''};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/6
$self{$section} ||= "ExtUtils::MM_Unix"->can($section) || sub { ""; }
l!l&&r!l&&!r
000
'ExtUtils::MM_Unix'->can($section) || sub { ''; }
l!l&&r!l&&!r
000
MC/DC0%0/3
$self{$section} ||= "ExtUtils::MM_Unix"->can($section) || sub { ""; }
$self{$section} 'ExtUtils::MM_Unix'->can($section) sub { ''; }
Truth table0%0/4
A ||= B || C
A= $self{$section}B= 'ExtUtils::MM_Unix'->can($section)C= sub { ''; }
ABCresult
1XX1
01X1
0011
0000
103 0 my $sub=sprintf('%s::MM::%s', ref($self), $section);
104 0 ▶ if (my $cr=*{$sub}{CODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cr = *{$sub;}{'CODE'}) { } 0 0 0
105 0 msg("import $section from $sub");
106 0 ▶ *{"ExtUtils::MM::${section}"}=sub { $cr->($self, @_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
107 }
108 else {
109 0 msg("import $section from %s", __PACKAGE__);
110 0 ▶ *{"ExtUtils::MM::${section}"}=sub { &{$section}($self, @_) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 }
112 }
113 }
114 0 msg("initializing $class import complete");
115  
116 }
117  
118  
119 0 ▶sub const_config {
Subroutine const_config: not called CC=12 SCAR=50.5
Pod documented
120  
121  
122 # Get self ref
123 #
124 #
125 0 my ($self, $mm_or, @param)=@_;
126 0 (my $section = (caller(0))[3]) =~ s/^.*:://;
127 0 msg("generating %s $section", ref($self));
128  
129  
130 # Get original const_config ready for append
131 #
132 0 my $const_config=$self->{$section}($mm_or, @param);
133  
134  
135 # Import Constants into macros
136 #
137 0 my $constant_hr=\%{sprintf('%s::MM::Constant::Constant', ref($self))};
138 0 foreach my $key (keys %{$constant_hr}) {
139  
140 # Update macros with our config
141 #
142 0 ▶ next if $key eq 'MM_PREFIX';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "MM_PREFIX" 0 0 0
143 0 my $value=$constant_hr->{$key};
144 0 msg("add macro: $key, value: $value");
145 0 $mm_or->{'macro'}{$key}=$value;
146  
147 }
148  
149  
150 # Update license data. Get license type and author
151 #
152 0 my $license=$mm_or->{'LICENSE'};
153 0 ▶ my @author=@{$mm_or->{'AUTHOR'} || []};
Condition0%0/2
$mm_or->{'AUTHOR'} || []
l!l
00
MC/DC0%0/1
$mm_or->{'AUTHOR'} || []
$mm_or->{'AUTHOR'}
Truth table0%0/2
A
A= $mm_or->{'AUTHOR'}
Aresult
11
00
154 0 my $author=shift(@author);
155  
156  
157 # Publish supplied values and enrich complete license metadata
158 #
159 0 ▶ $mm_or->{'macro'}{'LICENSE'}=$license if defined($license) && length($license);
Branch: 1 branch
BranchTrueFalseTotal
if defined $license and length $license 0 0 0
Condition0%0/3
defined $license and length $license
!ll&&!rl&&r
000
MC/DC0%0/2
defined $license and length $license
defined $license length $license
Truth table0%0/3
A and B
A= defined $licenseB= length $license
ABresult
0X0
100
111
160 0 ▶ $mm_or->{'macro'}{'AUTHOR'}=$author if defined($author) && length($author);
Branch: 1 branch
BranchTrueFalseTotal
if defined $author and length $author 0 0 0
Condition0%0/3
defined $author and length $author
!ll&&!rl&&r
000
MC/DC0%0/2
defined $author and length $author
defined $author length $author
Truth table0%0/3
A and B
A= defined $authorB= length $author
ABresult
0X0
100
111
161 0 ▶ if ($license && $author) {
Branch: 1 branch
BranchTrueFalseTotal
if ($license and $author) 0 0 0
Condition0%0/3
$license and $author
!ll&&!rl&&r
000
MC/DC0%0/2
$license and $author
$license $author
Truth table0%0/3
A and B
A= $licenseB= $author
ABresult
0X0
100
111
162 0 my @license_module=Software::LicenseUtils->guess_license_from_meta_key($license);
163 0 ▶ @license_module ||
Branch: 1 branch
BranchTrueFalseTotal
@license_module or return err("unable to determine correct license module from string: $license") 0 0 0
164 return err("unable to determine correct license module from string: $license");
165 0 ▶ (@license_module > 1) &&
Branch: 1 branch
BranchTrueFalseTotal
@license_module > 1 and return err("ambiguous license string: $license, resolves to %s", join(",", @license_module)) 0 0 0
166 return err("ambiguous license string: $license, resolves to %s", join(',', @license_module));
167 0 my $license_or=(shift @license_module)->new({holder => $author});
168 0 $mm_or->{'META_MERGE'}{'resources'}{'license'}=$license_or->url();
169 }
170  
171  
172 # Now construct final PERLRUN string
173 #
174 0 my $perlrun=&perlrun($self, $mm_or);
175 0 $mm_or->{'PERLRUN'}=$perlrun;
176  
177  
178 # Keep copy of DIST_DEFAULT
179 #
180 0 $mm_or->{'macro'}{'DIST_DEFAULT_TARGET'}=$mm_or->{'DIST_DEFAULT'};
181  
182  
183 # Return whatever our parent does
184 #
185 0 return $const_config;
186  
187  
188 }
189  
190  
191  
192 # MakeMaker::MY replacement depend section
193 #
194 0 ▶sub depend {
Subroutine depend: not called CC=6 SCAR=37.4
Pod documented
195  
196  
197 # Get self ref
198 #
199 0 my ($self, $mm_or, @param)=@_;
200 0 (my $section = (caller(0))[3]) =~ s/^.*:://;
201 0 msg("generating %s $section", ref($self));
202  
203  
204 # Get original and modify
205 #
206 0 my $depend=$self->{$section}($mm_or, @param);
207  
208  
209 # Add VERSION_FROM without replacing existing dependencies
210 #
211 0 ▶ $depend='' unless defined($depend);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $depend 0 0 0
212 0 ▶ if ($mm_or->{'VERSION_FROM'} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($mm_or->{"VERSION_FROM"} and not $depend =~ /^Makefile\s*:[^\n]*\$\(VERSION_FROM\)/m) 0 0 0
Condition0%0/3
$mm_or->{"VERSION_FROM"} and not $depend =~ /^Makefile\s*:[^\n]*\$\(VERSION_FROM\)/m
!ll&&!rl&&r
000
MC/DC0%0/2
$mm_or->{"VERSION_FROM"} and not $depend =~ /^Makefile\s*:[^\n]*\$\(VERSION_FROM\)/m
$mm_or->{"VERSION_FROM"} not $depend =~ /^Makefile\s*:[^\n]*\$\(VERSION_FROM\)/m
Truth table0%0/3
A and not(B)
A= $mm_or->{"VERSION_FROM"}B= not $depend =~ /^Makefile\s*:[^\n]*\$\(VERSION_FROM\)/m
ABresult
0X0
100
111
213 $depend!~/^Makefile\s*:[^\n]*\$\(VERSION_FROM\)/m) {
214 0 ▶ $depend.=$/ if length($depend) && substr($depend, -1) ne $/;
Branch: 1 branch
BranchTrueFalseTotal
if length $depend and substr($depend, -1) ne $/ 0 0 0
Condition0%0/3
length $depend and substr($depend, -1) ne $/
!ll&&!rl&&r
000
MC/DC0%0/2
length $depend and substr($depend, -1) ne $/
length $depend substr($depend, -1) ne $/
Truth table0%0/3
A and B
A= length $dependB= substr($depend, -1) ne $/
ABresult
0X0
100
111
215 0 $depend.='Makefile : $(VERSION_FROM)'.$/;
216 }
217 0 return $depend;
218  
219 }
220  
221  
222 # MakeMaker::MY replacement postamble section
223 #
224 0 ▶sub postamble {
Subroutine postamble: not called CC=3 SCAR=24.8
Pod documented
225  
226  
227 # Get self ref
228 #
229 0 my ($self, $mm_or, @param)=@_;
230 0 (my $section = (caller(0))[3]) =~ s/^.*:://;
231 0 msg("generating %s $section", ref($self));
232  
233  
234 # Get original postamble ready for append
235 #
236 0 my $postamble=$self->{$section}($mm_or, @param);
237  
238  
239 # Get this extension's postamble template
240 #
241 0 my $constant_hr=\%{sprintf('%s::MM::Constant::Constant', ref($self))};
242 0 ▶ if (my $patch_fn=$constant_hr->{'TEMPLATE_POSTAMBLE_FN'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $patch_fn = $constant_hr->{"TEMPLATE_POSTAMBLE_FN"}) 0 0 0
243  
244  
245 # Yes, exists as var so implement
246 #
247 0 msg('using template: %s', basename($patch_fn));
248  
249  
250 # Generate a platform-safe target command and append the template
251 #
252 0 ▶ my $mm_prefix=$constant_hr->{'MM_PREFIX'} || mm_prefix(ref($self));
Condition0%0/3
$constant_hr->{'MM_PREFIX'} || mm_prefix(ref $self)
l!l&&r!l&&!r
000
MC/DC0%0/2
$constant_hr->{'MM_PREFIX'} || mm_prefix(ref $self)
$constant_hr->{'MM_PREFIX'} mm_prefix(ref $self)
Truth table0%0/3
A || B
A= $constant_hr->{'MM_PREFIX'}B= mm_prefix(ref $self)
ABresult
1X1
011
000
253 0 my $pm_macro="${mm_prefix}_PM";
254 0 my $argv_macro="${mm_prefix}_PM_ARGV";
255 0 my $target_macro="${mm_prefix}_PM_TARGET";
256 0 my $pm_target=$mm_or->oneliner(sprintf(
257 'my $method=shift(@ARGV); $(%s)->$method($(%s), @ARGV)',
258 $pm_macro,
259 $argv_macro
260 ));
261 0 $pm_target=~s/^\$\(ABSPERLRUN\)/\$\(PERLRUN\) -M\$\($pm_macro\)/;
262 0 $postamble.="$target_macro=$pm_target$/";
263 0 $postamble.=slurp($patch_fn);
264  
265  
266 }
267  
268  
269 # All done, return result
270 #
271 0 return $postamble;
272  
273 }
274  
275  
276 0 ▶sub post_initialize {
Subroutine post_initialize: not called CC=14 SCAR=53.5
Pod documented
277  
278  
279 # Add license file, other support files here
280 #
281 0 my ($self, $mm_or, @param)=@_;
282 0 (my $section = (caller(0))[3]) =~ s/^.*:://;
283 0 msg("generating %s $section", ref($self));
284  
285  
286 # Get original postamble ready for append
287 #
288 0 my $post_initialize=$self->{$section}($mm_or, @param);
289  
290  
291 # Add license file
292 #
293 0 ▶ $mm_or->{'PM'}{'LICENSE'}='$(INST_LIBDIR)/$(BASEEXT)/LICENSE' if -e 'LICENSE';
Branch: 1 branch
BranchTrueFalseTotal
if -e "LICENSE" 0 0 0
294  
295  
296 # Don't install docs/tmp files etc.
297 #
298 0 my %pm=map { $_=>$mm_or->{'PM'}{$_} } grep { !/\.(?:md|xml|pod|bak|tmp|new|old|ref|0|1)$/ } keys %{$mm_or->{'PM'}};
299 0 $mm_or->{'PM'}=\%pm;
300  
301  
302 # Update and install Git ref if needed/available
303 #
304 0 my $devnull=File::Spec->devnull();
305 0 my $version_from_fn=$mm_or->{'VERSION_FROM'};
306 0 ▶ my $git_ref_fn=$version_from_fn && "${version_from_fn}.sha";
Condition0%0/2
$version_from_fn && "$version_from_fn.sha"
!ll
00
MC/DC0%0/1
$version_from_fn && "$version_from_fn.sha"
$version_from_fn
Truth table0%0/2
A
A= $version_from_fn
Aresult
00
11
307 0 ▶ if ($version_from_fn && -f $version_from_fn &&
Branch: 1 branch
BranchTrueFalseTotal
if ($version_from_fn and -f $version_from_fn and my $git_version = `git rev-parse --short HEAD 2>$devnull` and not $?) 0 0 0
Condition0%0/9
$version_from_fn and -f $version_from_fn and my $git_version = `git rev-parse --short HEAD 2>$devnull` and not $?
!ll&&!rl&&r
000
$version_from_fn and -f $version_from_fn and my $git_version = `git rev-parse --short HEAD 2>$devnull`
!ll&&!rl&&r
000
$version_from_fn and -f $version_from_fn
!ll&&!rl&&r
000
MC/DC0%0/4
$version_from_fn and -f $version_from_fn and my $git_version = `git rev-parse --short HEAD 2>$devnull` and not $?
$version_from_fn -f $version_from_fn my $git_version = `git rev-parse --short HEAD 2>$devnull` not $?
Truth table0%0/5
A and B and C and not(D)
A= $version_from_fnB= -f $version_from_fnC= my $git_version = `git rev-parse --short HEAD 2>$devnull`D= not $?
ABCDresult
0XXX0
10XX0
110X0
11100
11111
308 (my $git_version=qx(git rev-parse --short HEAD 2>$devnull)) && !$?) {
309 0 chomp($git_version);
310 0 ▶ tie(my @lines, 'Tie::File', $git_ref_fn) ||
Branch: 1 branch
BranchTrueFalseTotal
tie my @lines, "Tie::File", $git_ref_fn or die "error on Tie::File, $!" 0 0 0
311 die("error on Tie::File, $!");
312 0 ▶ @lines=($git_version)
Branch: 1 branch
BranchTrueFalseTotal
unless @lines == 1 and $lines[0] eq $git_version 0 0 0
Condition0%0/3
@lines == 1 and $lines[0] eq $git_version
!ll&&!rl&&r
000
MC/DC0%0/2
@lines == 1 and $lines[0] eq $git_version
@lines == 1 $lines[0] eq $git_version
Truth table0%0/3
A and B
A= @lines == 1B= $lines[0] eq $git_version
ABresult
0X0
100
111
313 unless @lines==1 && $lines[0] eq $git_version;
314 }
315 0 ▶ if ($git_ref_fn && -f $git_ref_fn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($git_ref_fn and -f $git_ref_fn) 0 0 0
Condition0%0/3
$git_ref_fn and -f $git_ref_fn
!ll&&!rl&&r
000
MC/DC0%0/2
$git_ref_fn and -f $git_ref_fn
$git_ref_fn -f $git_ref_fn
Truth table0%0/3
A and B
A= $git_ref_fnB= -f $git_ref_fn
ABresult
0X0
100
111
316 0 ▶ if ($mm_or->{'PM'}{$version_from_fn}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mm_or->{'PM'}{$version_from_fn}) { } 0 0 0
elsif (grep {$version_from_fn eq $_;} @{$$mm_or{'EXE_FILES'};}) { } 0 0 0
317 0 $mm_or->{'PM'}{$git_ref_fn}=$mm_or->{'PM'}{$version_from_fn}.'.sha';
318 }
319 0 elsif (grep {$version_from_fn eq $_} @{$mm_or->{'EXE_FILES'}}) {
320 0 (my $git_ref_base_fn=$git_ref_fn)=~s{^.*[/\\]}{};
321 0 $mm_or->{'PM'}{$git_ref_fn}='$(INST_SCRIPT)/'.$git_ref_base_fn;
322 }
323 }
324  
325 # Done
326 #
327 0 return $post_initialize
328  
329 }
330  
331  
332 # Construct a default Makefile macro prefix from an extension class
333 #
334 1 ▶sub mm_prefix {
Subroutine mm_prefix: called CC=1 SCAR=0.0
Pod undocumented
335  
336 1 my $class=shift();
337 1 $class=~s/::/_/g;
338 1 return uc($class)
339  
340 }
341  
342  
343 # Not used yet
344 #
345 0 ▶sub special_targets {
Subroutine special_targets: not called CC=1 SCAR=6.9
Pod undocumented
346  
347 0 my ($self, $mm_or, @param)=@_;
348 0 (my $section = (caller(0))[3]) =~ s/^.*:://;
349 0 msg("generating %s $section", ref($self));
350  
351 0 my $special_targets=$self->{$section}($mm_or, @param);
352 0 $special_targets=~s/\.PHONY:\s+(.*)/\.PHONY: $1 cpanfile/m;
353 0 return $special_targets;
354  
355 }
356  
357  
358  
359 __END__
↑ Summary blib/lib/ASPEER/MakeMaker.pm »