| 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 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use vars qw($VERSION $VERSION_GIT_SHA $AUTHORITY); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # Base packages | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use ASPEER::MakeMaker::MM::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # Other modules | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use File::Basename qw(dirname basename); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use File::Temp qw(tempfile); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | local $Data::Dumper::Sortkeys=1; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # Version information | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | $AUTHORITY='cpan:ASPEER'; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | $VERSION='1.011'; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | $VERSION_GIT_SHA=do { local(@ARGV, $/, $_); @ARGV=($_=__FILE__.'.sha'); <> if -f $_ }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | chomp($VERSION_GIT_SHA) if defined($VERSION_GIT_SHA); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Init Done | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 47 | #============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # Forward import on to dedicated module | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | push (@_, qw(const_config postamble)) unless $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | require ASPEER::MakeMaker::MM::Import; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | 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=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my ($self, $param_hr)=(shift(), arg(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | print Dumper($param_hr); | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | # Copy template files from this module to target | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | sub util_sync { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
util_sync: called CC=31 SCAR=42.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | my ($self, $param_hr)=(shift(), arg(@_)); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | my ($srce_pn)=@{$param_hr->{'ARGV_AR'}}; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Get dest | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | msg('util_sync start'); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | my $srce_fn=basename($srce_pn) || | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
basename($srce_pn) || (return err("unable to get basebane from path: $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)
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | return err("unable to get basebane from path: $srce_pn"); | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | ▶ | my $to_inst_pm_ar=$param_hr->{'TO_INST_PM_AR'} || | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$param_hr->{'TO_INST_PM_AR'} || (return err('unable to get TO_INST_PM_AR Makefile param'))
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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | return err('unable to get TO_INST_PM_AR Makefile param'); | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | my ($dest_pn)=(grep { /MM\/${srce_fn}$/ } @{$to_inst_pm_ar}); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | $dest_pn || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | die "usage: $self->util_sync(..., source_filename)\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$srce_pn and $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
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | unless $srce_pn && $dest_pn; | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | ▶ | die "source file not found: $srce_pn\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | unless -e $srce_pn; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | ▶ | die "source is not a regular file: $srce_pn\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | unless -f _; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | die "source is not readable: $srce_pn\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | unless -r _; | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | my $dest_dir=dirname($dest_pn); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | ▶ | die "destination directory not found: $dest_dir\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | unless -d $dest_dir; | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | my $srce_abs=File::Spec->rel2abs($srce_pn); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | my $dest_abs=File::Spec->rel2abs($dest_pn); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | ▶ | die "source and destination are the same path: $srce_abs\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | if $srce_abs eq $dest_abs; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | my @srce_stat=stat($srce_pn) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | or die "stat failed for source $srce_pn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | ▶ | if (-e $dest_pn) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 1 | ▶ | my @dest_stat=stat($dest_pn) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | or die "stat failed for destination $dest_pn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | ▶ | die "source and destination are the same file: $srce_pn -> $dest_pn\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$srce_stat[0] == $dest_stat[0] and $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]
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | if $srce_stat[0] == $dest_stat[0] && $srce_stat[1] == $dest_stat[1]; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | my ($tmp_fh, $tmp_fn)=tempfile('.util_sync.XXXXXXXX', DIR => $dest_dir); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | close($tmp_fh) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | or die "close failed for temporary file $tmp_fn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | my $text=slurp($srce_pn); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | my $name=$param_hr->{'NAME'} || | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$param_hr->{'NAME'} || die("target module name unavailable for $dest_pn\n")
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'}
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | die "target module name unavailable for $dest_pn\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | my $version=$param_hr->{'VERSION'}; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | my $version_from_fn=$param_hr->{'VERSION_FROM'}; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | if ($version_from_fn && -f $version_from_fn) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$version_from_fn and -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
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | require ExtUtils::MakeMaker; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | my $version_from=MM->parse_version($version_from_fn); | |||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | $version=$version_from | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $version_from and length $version_from and $version_from ne "undef"
defined $version_from and length $version_from
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | if defined($version_from) && length($version_from) && $version_from ne 'undef'; | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | $text=~s/\Q$self\E/$name/g; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | $text=~s/(\$VERSION\s*=\s*')[^']*(';)/$1$version$2/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $version and 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
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | if defined($version) && length($version); | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | blurp($tmp_fn, $text); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | chmod($srce_stat[2] & 07777, $tmp_fn) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | or die "chmod failed for temporary file $tmp_fn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ▶ | utime($srce_stat[8], $srce_stat[9], $tmp_fn) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | or die "utime failed for temporary file $tmp_fn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | ▶ | rename($tmp_fn, $dest_pn) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | or die "rename failed from $tmp_fn to $dest_pn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | my $err=$@ || 'unknown error'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$@ || 'unknown error'
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | unlink($tmp_fn) if -e $tmp_fn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | die $err; | |||||||||||||||||||||||||||||||||||||||||
| 157 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | msg("updated $dest_pn"); | |||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | __END__ | ||||||||||||||||||||||||||||||||||||||||||