ASPEER-MakeMaker
view release on metacpan or search on metacpan
lib/ASPEER/MakeMaker.pm view on Meta::CPAN
#
use ASPEER::MakeMaker::MM::Util;
# Other modules
#
use File::Basename qw(dirname basename);
use File::Spec;
use File::Temp qw(tempfile);
local $Data::Dumper::Sortkeys=1;
# Version information
#
$AUTHORITY='cpan:ASPEER';
$VERSION='1.012';
$VERSION_GIT_SHA=do { local(@ARGV, $/, $_); @ARGV=($_=__FILE__.'.sha'); <> if -f $_ };
chomp($VERSION_GIT_SHA) if defined($VERSION_GIT_SHA);
# Init Done
#
1;
#==============================================================================
#
# Forward import on to dedicated module
#
sub import {
push (@_, qw(const_config postamble)) unless $_[1];
require ASPEER::MakeMaker::MM::Import;
goto &ASPEER::MakeMaker::MM::Import::import;
}
#==============================================================================
#
# Methods to support Makefile targets from here on
#
sub dump_param {
my ($self, $param_hr)=(shift(), arg(@_));
print Dumper($param_hr);
}
# Copy template files from this module to target
#
sub util_sync {
my ($self, $param_hr)=(shift(), arg(@_));
my ($srce_pn)=@{$param_hr->{'ARGV_AR'}};
# Get dest
#
msg('util_sync start');
my $srce_fn=basename($srce_pn) ||
return err("unable to get basebane from path: $srce_pn");
my $to_inst_pm_ar=$param_hr->{'TO_INST_PM_AR'} ||
return err('unable to get TO_INST_PM_AR Makefile param');
my ($dest_pn)=(grep { /MM\/${srce_fn}$/ } @{$to_inst_pm_ar});
$dest_pn ||
return err("unable to get destination for $srce_fn from TO_INST_PM_AR: %s, dest file must exist !", Dumper($to_inst_pm_ar));
die "usage: $self->util_sync(..., source_filename)\n"
unless $srce_pn && $dest_pn;
die "source file not found: $srce_pn\n"
unless -e $srce_pn;
die "source is not a regular file: $srce_pn\n"
unless -f _;
die "source is not readable: $srce_pn\n"
unless -r _;
my $dest_dir=dirname($dest_pn);
die "destination directory not found: $dest_dir\n"
unless -d $dest_dir;
my $srce_abs=File::Spec->rel2abs($srce_pn);
my $dest_abs=File::Spec->rel2abs($dest_pn);
die "source and destination are the same path: $srce_abs\n"
if $srce_abs eq $dest_abs;
my @srce_stat=stat($srce_pn)
or die "stat failed for source $srce_pn: $!\n";
if (-e $dest_pn) {
my @dest_stat=stat($dest_pn)
or die "stat failed for destination $dest_pn: $!\n";
die "source and destination are the same file: $srce_pn -> $dest_pn\n"
if $srce_stat[0] == $dest_stat[0] && $srce_stat[1] == $dest_stat[1];
}
my ($tmp_fh, $tmp_fn)=tempfile('.util_sync.XXXXXXXX', DIR => $dest_dir);
close($tmp_fh)
or die "close failed for temporary file $tmp_fn: $!\n";
eval {
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 && -f $version_from_fn) {
require ExtUtils::MakeMaker;
my $version_from=MM->parse_version($version_from_fn);
$version=$version_from
if defined($version_from) && length($version_from) && $version_from ne 'undef';
}
$text=~s/\Q$self\E/$name/g;
$text=~s/(\$VERSION\s*=\s*')[^']*(';)/$1$version$2/
if defined($version) && length($version);
( run in 0.575 second using v1.01-cache-2.11-cpan-234fa220139 )