lib/ASPEER/MakeMaker.pm

filter: Statementstmt 66.6% 88 / 132 Branchbran 30.6% 27 / 88 Conditioncond 17.3% 9 / 52 MC/DCmcdc 0.0% 0 / 30 Subroutinesub 84.6% 11 / 13 Podpod 100% 4 / 4 totaltotal 43.5% 139 / 319 CC 63 SCAR 54.9
CC
63
Cov
46%
util_sync
291.7
util_sync
291.7
import
2.0
CRAP 241.3
↑ Summary lib/ASPEER/MakeMaker/MM/Import.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;
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 $VERSION_GIT_SHA $AUTHORITY);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Base packages
24 #
25 3 ▶use ASPEER::MakeMaker::MM::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27  
28 # Other modules
29 #
30 3 ▶use File::Basename qw(dirname basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 local $Data::Dumper::Sortkeys=1;
34  
35  
36 # Version information
37 #
38 1 $AUTHORITY='cpan:ASPEER';
39 1 $VERSION='1.012';
40 1 ▶$VERSION_GIT_SHA=do { local(@ARGV, $/, $_); @ARGV=($_=__FILE__.'.sha'); <> if -f $_ };
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ 0 1 1
41 1 ▶chomp($VERSION_GIT_SHA) if defined($VERSION_GIT_SHA);
Branch: 1 branch
BranchTrueFalseTotal
if defined $ASPEER::MakeMaker::VERSION_GIT_SHA 0 1 1
42  
43  
44 # Init Done
45 #
46 1 1;
47 #==============================================================================
48 #
49 # Forward import on to dedicated module
50 #
51 1 ▶sub import {
Subroutine import: called CC=2 SCAR=7.0
52  
53 2 ▶ push (@_, qw(const_config postamble)) unless $_[1];
Subroutine import: called CC=2 SCAR=7.0
Branch: 2 branches
BranchTrueFalseTotal
unless $_[1] 1 0 1
unless $_[1] 1 2 3
54 2 require ASPEER::MakeMaker::MM::Import;
55 2 goto &ASPEER::MakeMaker::MM::Import::import;
56  
57 }
58  
59  
60  
61 #==============================================================================
62 #
63 # Methods to support Makefile targets from here on
64 #
65 0 ▶sub dump_param {
Subroutine dump_param: not called CC=1 SCAR=0.0
Pod documented
66  
67 2 ▶ my ($self, $param_hr)=(shift(), arg(@_));
Subroutine dump_param: called CC=1 SCAR=0.0
Pod documented
68 2 print Dumper($param_hr);
69  
70 }
71  
72  
73  
74 # Copy template files from this module to target
75 #
76 0 ▶sub util_sync {
Subroutine util_sync: not called CC=31 SCAR=56.8
Pod documented
77  
78 2 ▶ my ($self, $param_hr)=(shift(), arg(@_));
Subroutine util_sync: called CC=31 SCAR=56.8
Pod documented
79 2 my ($srce_pn)=@{$param_hr->{'ARGV_AR'}};
80  
81  
82 # Get dest
83 #
84 2 msg('util_sync start');
85 0 ▶ my $srce_fn=basename($srce_pn) ||
Condition25%1/4
basename($srce_pn) || (return err("unable to get basebane from path: $srce_pn"))
l!l
30
basename($srce_pn) || (return err("unable to get basebane from path: $srce_pn"))
l!l
00
MC/DC0%0/1
basename($srce_pn) || (return err("unable to get basebane from path: $srce_pn"))
basename($srce_pn)
MC/DC0%0/1
basename($srce_pn) || (return err("unable to get basebane from path: $srce_pn"))
basename($srce_pn)
Truth table50%1/2
A
A= basename($srce_pn)
Aresult
11
00
Truth table0%0/2
A
A= basename($srce_pn)
Aresult
11
00
86 return err("unable to get basebane from path: $srce_pn");
87 0 ▶ my $to_inst_pm_ar=$param_hr->{'TO_INST_PM_AR'} ||
Condition25%1/4
$param_hr->{'TO_INST_PM_AR'} || (return err('unable to get TO_INST_PM_AR Makefile param'))
l!l
30
$param_hr->{'TO_INST_PM_AR'} || (return err('unable to get TO_INST_PM_AR Makefile param'))
l!l
00
MC/DC0%0/1
$param_hr->{'TO_INST_PM_AR'} || (return err('unable to get TO_INST_PM_AR Makefile param'))
$param_hr->{'TO_INST_PM_AR'}
MC/DC0%0/1
$param_hr->{'TO_INST_PM_AR'} || (return err('unable to get TO_INST_PM_AR Makefile param'))
$param_hr->{'TO_INST_PM_AR'}
Truth table50%1/2
A
A= $param_hr->{'TO_INST_PM_AR'}
Aresult
11
00
Truth table0%0/2
A
A= $param_hr->{'TO_INST_PM_AR'}
Aresult
11
00
88 return err('unable to get TO_INST_PM_AR Makefile param');
89 0 my ($dest_pn)=(grep { /MM\/${srce_fn}$/ } @{$to_inst_pm_ar});
90 0 ▶ $dest_pn ||
Branch: 2 branches
BranchTrueFalseTotal
$dest_pn or return err("unable to get destination for $srce_fn from TO_INST_PM_AR: %s, dest file must exist !", Dumper($to_inst_pm_ar)) 3 0 3
$dest_pn or return err("unable to get destination for $srce_fn from TO_INST_PM_AR: %s, dest file must exist !", Dumper($to_inst_pm_ar)) 0 2 2
91 return err("unable to get destination for $srce_fn from TO_INST_PM_AR: %s, dest file must exist !", Dumper($to_inst_pm_ar));
92  
93  
94 0 ▶ die "usage: $self->util_sync(..., source_filename)\n"
Branch: 2 branches
BranchTrueFalseTotal
unless $srce_pn and $dest_pn 0 3 3
unless $srce_pn and $dest_pn 0 0 0
Condition16%1/6
$srce_pn and $dest_pn
!ll&&!rl&&r
003
$srce_pn and $dest_pn
!ll&&!rl&&r
000
MC/DC0%0/2
$srce_pn and $dest_pn
$srce_pn $dest_pn
MC/DC0%0/2
$srce_pn and $dest_pn
$srce_pn $dest_pn
Truth table33%1/3
A and B
A= $srce_pnB= $dest_pn
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $srce_pnB= $dest_pn
ABresult
0X0
100
111
95 unless $srce_pn && $dest_pn;
96  
97 0 ▶ die "source file not found: $srce_pn\n"
Branch: 2 branches
BranchTrueFalseTotal
unless -e $srce_pn 0 3 3
unless -e $srce_pn 0 0 0
98 unless -e $srce_pn;
99 0 ▶ die "source is not a regular file: $srce_pn\n"
Branch: 2 branches
BranchTrueFalseTotal
unless -f _ 0 3 3
unless -f _ 0 0 0
100 unless -f _;
101 0 ▶ die "source is not readable: $srce_pn\n"
Branch: 2 branches
BranchTrueFalseTotal
unless -r _ 0 3 3
unless -r _ 0 0 0
102 unless -r _;
103  
104 0 my $dest_dir=dirname($dest_pn);
105 0 ▶ die "destination directory not found: $dest_dir\n"
Branch: 2 branches
BranchTrueFalseTotal
unless -d $dest_dir 0 3 3
unless -d $dest_dir 0 0 0
106 unless -d $dest_dir;
107  
108 0 my $srce_abs=File::Spec->rel2abs($srce_pn);
109 0 my $dest_abs=File::Spec->rel2abs($dest_pn);
110 0 ▶ die "source and destination are the same path: $srce_abs\n"
Branch: 2 branches
BranchTrueFalseTotal
if $srce_abs eq $dest_abs 1 2 3
if $srce_abs eq $dest_abs 0 0 0
111 if $srce_abs eq $dest_abs;
112  
113 0 ▶ my @srce_stat=stat($srce_pn)
Branch: 2 branches
BranchTrueFalseTotal
my(@srce_stat) = stat $srce_pn or die "stat failed for source ${srce_pn}: $!\n" 2 0 2
my(@srce_stat) = stat $srce_pn or die "stat failed for source ${srce_pn}: $!\n" 0 0 0
114 or die "stat failed for source $srce_pn: $!\n";
115  
116 0 ▶ if (-e $dest_pn) {
Branch: 2 branches
BranchTrueFalseTotal
if (-e $dest_pn) 1 1 2
if (-e $dest_pn) 0 0 0
117  
118 0 ▶ my @dest_stat=stat($dest_pn)
Branch: 2 branches
BranchTrueFalseTotal
my(@dest_stat) = stat $dest_pn or die "stat failed for destination ${dest_pn}: $!\n" 1 0 1
my(@dest_stat) = stat $dest_pn or die "stat failed for destination ${dest_pn}: $!\n" 0 0 0
119 or die "stat failed for destination $dest_pn: $!\n";
120  
121 0 ▶ die "source and destination are the same file: $srce_pn -> $dest_pn\n"
Branch: 2 branches
BranchTrueFalseTotal
if $srce_stat[0] == $dest_stat[0] and $srce_stat[1] == $dest_stat[1] 0 1 1
if $srce_stat[0] == $dest_stat[0] and $srce_stat[1] == $dest_stat[1] 0 0 0
Condition16%1/6
$srce_stat[0] == $dest_stat[0] and $srce_stat[1] == $dest_stat[1]
!ll&&!rl&&r
010
$srce_stat[0] == $dest_stat[0] and $srce_stat[1] == $dest_stat[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$srce_stat[0] == $dest_stat[0] and $srce_stat[1] == $dest_stat[1]
$srce_stat[0] == $dest_stat[0] $srce_stat[1] == $dest_stat[1]
MC/DC0%0/2
$srce_stat[0] == $dest_stat[0] and $srce_stat[1] == $dest_stat[1]
$srce_stat[0] == $dest_stat[0] $srce_stat[1] == $dest_stat[1]
Truth table33%1/3
A and B
A= $srce_stat[0] == $dest_stat[0]B= $srce_stat[1] == $dest_stat[1]
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $srce_stat[0] == $dest_stat[0]B= $srce_stat[1] == $dest_stat[1]
ABresult
0X0
100
111
122 if $srce_stat[0] == $dest_stat[0] && $srce_stat[1] == $dest_stat[1];
123  
124 }
125  
126 0 my ($tmp_fh, $tmp_fn)=tempfile('.util_sync.XXXXXXXX', DIR => $dest_dir);
127 0 ▶ close($tmp_fh)
Branch: 2 branches
BranchTrueFalseTotal
close $tmp_fh or die "close failed for temporary file ${tmp_fn}: $!\n" 2 0 2
close $tmp_fh or die "close failed for temporary file ${tmp_fn}: $!\n" 0 0 0
128 or die "close failed for temporary file $tmp_fn: $!\n";
129  
130 eval {
131 0 my $text=slurp($srce_pn);
132 0 ▶ my $name=$param_hr->{'NAME'} ||
Condition25%1/4
$param_hr->{'NAME'} || die("target module name unavailable for $dest_pn\n")
l!l
20
$param_hr->{'NAME'} || die("target module name unavailable for $dest_pn\n")
l!l
00
MC/DC0%0/1
$param_hr->{'NAME'} || die("target module name unavailable for $dest_pn\n")
$param_hr->{'NAME'}
MC/DC0%0/1
$param_hr->{'NAME'} || die("target module name unavailable for $dest_pn\n")
$param_hr->{'NAME'}
Truth table50%1/2
A
A= $param_hr->{'NAME'}
Aresult
11
00
Truth table0%0/2
A
A= $param_hr->{'NAME'}
Aresult
11
00
133 die "target module name unavailable for $dest_pn\n";
134 0 my $version=$param_hr->{'VERSION'};
135 0 my $version_from_fn=$param_hr->{'VERSION_FROM'};
136 0 ▶ if ($version_from_fn && -f $version_from_fn) {
Branch: 2 branches
BranchTrueFalseTotal
if ($version_from_fn and -f $version_from_fn) 2 0 2
if ($version_from_fn and -f $version_from_fn) 0 0 0
Condition16%1/6
$version_from_fn and -f $version_from_fn
!ll&&!rl&&r
002
$version_from_fn and -f $version_from_fn
!ll&&!rl&&r
000
MC/DC0%0/2
$version_from_fn and -f $version_from_fn
$version_from_fn -f $version_from_fn
MC/DC0%0/2
$version_from_fn and -f $version_from_fn
$version_from_fn -f $version_from_fn
Truth table33%1/3
A and B
A= $version_from_fnB= -f $version_from_fn
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $version_from_fnB= -f $version_from_fn
ABresult
0X0
100
111
137 0 require ExtUtils::MakeMaker;
138 0 my $version_from=MM->parse_version($version_from_fn);
139 0 ▶ $version=$version_from
Branch: 2 branches
BranchTrueFalseTotal
if defined $version_from and length $version_from and $version_from ne "undef" 2 0 2
if defined $version_from and length $version_from and $version_from ne "undef" 0 0 0
Condition16%2/12
defined $version_from and length $version_from and $version_from ne "undef"
!ll&&!rl&&r
002
defined $version_from and length $version_from
!ll&&!rl&&r
002
defined $version_from and length $version_from and $version_from ne "undef"
!ll&&!rl&&r
000
defined $version_from and length $version_from
!ll&&!rl&&r
000
MC/DC0%0/3
defined $version_from and length $version_from and $version_from ne "undef"
defined $version_from length $version_from $version_from ne "undef"
MC/DC0%0/3
defined $version_from and length $version_from and $version_from ne "undef"
defined $version_from length $version_from $version_from ne "undef"
Truth table25%1/4
A and B and C
A= defined $version_fromB= length $version_fromC= $version_from ne "undef"
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= defined $version_fromB= length $version_fromC= $version_from ne "undef"
ABCresult
0XX0
10X0
1100
1111
140 if defined($version_from) && length($version_from) && $version_from ne 'undef';
141 }
142 0 $text=~s/\Q$self\E/$name/g;
143 0 ▶ $text=~s/(\$VERSION\s*=\s*')[^']*(';)/$1$version$2/
Branch: 2 branches
BranchTrueFalseTotal
if defined $version and length $version 2 0 2
if defined $version and length $version 0 0 0
Condition16%1/6
defined $version and length $version
!ll&&!rl&&r
002
defined $version and length $version
!ll&&!rl&&r
000
MC/DC0%0/2
defined $version and length $version
defined $version length $version
MC/DC0%0/2
defined $version and length $version
defined $version length $version
Truth table33%1/3
A and B
A= defined $versionB= length $version
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $versionB= length $version
ABresult
0X0
100
111
144 if defined($version) && length($version);
145 0 blurp($tmp_fn, $text);
146 0 ▶ chmod($srce_stat[2] & 07777, $tmp_fn)
Branch: 2 branches
BranchTrueFalseTotal
chmod $srce_stat[2] & 4095, $tmp_fn or die "chmod failed for temporary file ${tmp_fn}: $!\n" 2 0 2
chmod $srce_stat[2] & 4095, $tmp_fn or die "chmod failed for temporary file ${tmp_fn}: $!\n" 0 0 0
147 or die "chmod failed for temporary file $tmp_fn: $!\n";
148 0 ▶ utime($srce_stat[8], $srce_stat[9], $tmp_fn)
Branch: 2 branches
BranchTrueFalseTotal
utime $srce_stat[8], $srce_stat[9], $tmp_fn or die "utime failed for temporary file ${tmp_fn}: $!\n" 2 0 2
utime $srce_stat[8], $srce_stat[9], $tmp_fn or die "utime failed for temporary file ${tmp_fn}: $!\n" 0 0 0
149 or die "utime failed for temporary file $tmp_fn: $!\n";
150 0 ▶ rename($tmp_fn, $dest_pn)
Branch: 2 branches
BranchTrueFalseTotal
rename $tmp_fn, $dest_pn or die "rename failed from $tmp_fn to ${dest_pn}: $!\n" 2 0 2
rename $tmp_fn, $dest_pn or die "rename failed from $tmp_fn to ${dest_pn}: $!\n" 0 0 0
151 or die "rename failed from $tmp_fn to $dest_pn: $!\n";
152 0 1;
153 0 ▶ } or do {
Branch: 2 branches
BranchTrueFalseTotal
eval { do { my $text = slurp($srce_pn); my $name = $param_hr->{"NAME"} || die("target module name unavailable for $dest_pn\n"); my $version = $param_hr->{"VERSION"}; my $version_from_fn = $param_hr->{"VERSION_FROM"}; if ($version_from_fn and -f $version_from_fn) { require ExtUtils::MakeMaker; my $version_from = "MM"->parse_version($version_from_fn); $version = $version_from if defined $version_from and length $version_from and $version_from ne "undef"; } ; $text =~ s/\Q$self\E/$name/g; $text =~ s/(\$VERSION\s*=\s*')[^']*(';)/$1$version$2/ if defined $version and length $version; blurp($tmp_fn, $text); chmod $srce_stat[2] & 4095, $tmp_fn or die "chmod failed for temporary file ${tmp_fn}: $!\n"; utime $srce_stat[8], $srce_stat[9], $tmp_fn or die "utime failed for temporary file ${tmp_fn}: $!\n"; rename $tmp_fn, $dest_pn or die "rename failed from $tmp_fn to ${dest_pn}: $!\n"; 1 } } or do { my $err = $@ || "unknown error"; unlink $tmp_fn if -e $tmp_fn; die $err } 2 0 2
eval { do { my $text = slurp($srce_pn); my $name = $param_hr->{"NAME"} || die("target module name unavailable for $dest_pn\n"); my $version = $param_hr->{"VERSION"}; my $version_from_fn = $param_hr->{"VERSION_FROM"}; if ($version_from_fn and -f $version_from_fn) { require ExtUtils::MakeMaker; my $version_from = "MM"->parse_version($version_from_fn); $version = $version_from if defined $version_from and length $version_from and $version_from ne "undef"; } ; $text =~ s/\Q$self\E/$name/g; $text =~ s/(\$VERSION\s*=\s*')[^']*(';)/$1$version$2/ if defined $version and length $version; blurp($tmp_fn, $text); chmod $srce_stat[2] & 4095, $tmp_fn or die "chmod failed for temporary file ${tmp_fn}: $!\n"; utime $srce_stat[8], $srce_stat[9], $tmp_fn or die "utime failed for temporary file ${tmp_fn}: $!\n"; rename $tmp_fn, $dest_pn or die "rename failed from $tmp_fn to ${dest_pn}: $!\n"; 1 } } or do { my $err = $@ || "unknown error"; unlink $tmp_fn if -e $tmp_fn; die $err } 0 0 0
154 0 ▶ my $err=$@ || 'unknown error';
Condition0%0/4
$@ || 'unknown error'
l!l
00
$@ || 'unknown error'
l!l
00
MC/DC0%0/1
$@ || 'unknown error'
$@
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
Truth table0%0/2
A
A= $@
Aresult
11
00
155 0 ▶ unlink($tmp_fn) if -e $tmp_fn;
Branch: 2 branches
BranchTrueFalseTotal
if -e $tmp_fn 0 0 0
if -e $tmp_fn 0 0 0
156 0 die $err;
157 };
158  
159  
160 0 msg("updated $dest_pn");
161 0 return 1;
162 }
163  
164 __END__
↑ Summary lib/ASPEER/MakeMaker/MM/Import.pm »