ASPEER-MakeMaker
view release on metacpan or search on metacpan
lib/ASPEER/MakeMaker/MM/Import.pm view on Meta::CPAN
if (my $cr=*{$sub}{CODE}) {
msg("import $section from $sub");
*{"ExtUtils::MM::${section}"}=sub { $cr->($self, @_) };
}
else {
msg("import $section from %s", __PACKAGE__);
*{"ExtUtils::MM::${section}"}=sub { &{$section}($self, @_) };
}
}
}
msg("initializing $class import complete");
}
sub const_config {
# Get self ref
#
#
my ($self, $mm_or, @param)=@_;
(my $section = (caller(0))[3]) =~ s/^.*:://;
msg("generating %s $section", ref($self));
# Get original const_config ready for append
#
my $const_config=$self->{$section}($mm_or, @param);
# Import Constants into macros
#
my $constant_hr=\%{sprintf('%s::MM::Constant::Constant', ref($self))};
foreach my $key (keys %{$constant_hr}) {
# Update macros with our config
#
next if $key eq 'MM_PREFIX';
my $value=$constant_hr->{$key};
msg("add macro: $key, value: $value");
$mm_or->{'macro'}{$key}=$value;
}
# Update license data. Get license type and author
#
my $license=$mm_or->{'LICENSE'};
my @author=@{$mm_or->{'AUTHOR'} || []};
my $author=shift(@author);
# Publish supplied values and enrich complete license metadata
#
$mm_or->{'macro'}{'LICENSE'}=$license if defined($license) && length($license);
$mm_or->{'macro'}{'AUTHOR'}=$author if defined($author) && length($author);
if ($license && $author) {
my @license_module=Software::LicenseUtils->guess_license_from_meta_key($license);
@license_module ||
return err("unable to determine correct license module from string: $license");
(@license_module > 1) &&
return err("ambiguous license string: $license, resolves to %s", join(',', @license_module));
my $license_or=(shift @license_module)->new({holder => $author});
$mm_or->{'META_MERGE'}{'resources'}{'license'}=$license_or->url();
}
# Now construct final PERLRUN string
#
my $perlrun=&perlrun($self, $mm_or);
$mm_or->{'PERLRUN'}=$perlrun;
# Keep copy of DIST_DEFAULT
#
$mm_or->{'macro'}{'DIST_DEFAULT_TARGET'}=$mm_or->{'DIST_DEFAULT'};
# Return whatever our parent does
#
return $const_config;
}
# MakeMaker::MY replacement depend section
#
sub depend {
# Get self ref
#
my ($self, $mm_or, @param)=@_;
(my $section = (caller(0))[3]) =~ s/^.*:://;
msg("generating %s $section", ref($self));
# Get original and modify
#
my $depend=$self->{$section}($mm_or, @param);
# Add VERSION_FROM without replacing existing dependencies
#
$depend='' unless defined($depend);
if ($mm_or->{'VERSION_FROM'} &&
$depend!~/^Makefile\s*:[^\n]*\$\(VERSION_FROM\)/m) {
$depend.=$/ if length($depend) && substr($depend, -1) ne $/;
$depend.='Makefile : $(VERSION_FROM)'.$/;
}
return $depend;
}
# MakeMaker::MY replacement postamble section
#
sub postamble {
lib/ASPEER/MakeMaker/MM/Import.pm view on Meta::CPAN
#
my $mm_prefix=$constant_hr->{'MM_PREFIX'} || mm_prefix(ref($self));
my $pm_macro="${mm_prefix}_PM";
my $argv_macro="${mm_prefix}_PM_ARGV";
my $target_macro="${mm_prefix}_PM_TARGET";
my $pm_target=$mm_or->oneliner(sprintf(
'my $method=shift(@ARGV); $(%s)->$method($(%s), @ARGV)',
$pm_macro,
$argv_macro
));
$pm_target=~s/^\$\(ABSPERLRUN\)/\$\(PERLRUN\) -M\$\($pm_macro\)/;
$postamble.="$target_macro=$pm_target$/";
$postamble.=slurp($patch_fn);
}
# All done, return result
#
return $postamble;
}
sub post_initialize {
# Add license file, other support files here
#
my ($self, $mm_or, @param)=@_;
(my $section = (caller(0))[3]) =~ s/^.*:://;
msg("generating %s $section", ref($self));
# Get original postamble ready for append
#
my $post_initialize=$self->{$section}($mm_or, @param);
# Add license file
#
$mm_or->{'PM'}{'LICENSE'}='$(INST_LIBDIR)/$(BASEEXT)/LICENSE' if -e 'LICENSE';
# Don't install docs/tmp files etc.
#
my %pm=map { $_=>$mm_or->{'PM'}{$_} } grep { !/\.(?:md|xml|pod|bak|tmp|new|old|ref|0|1)$/ } keys %{$mm_or->{'PM'}};
$mm_or->{'PM'}=\%pm;
# Update and install Git ref if needed/available
#
my $devnull=File::Spec->devnull();
my $version_from_fn=$mm_or->{'VERSION_FROM'};
my $git_ref_fn=$version_from_fn && "${version_from_fn}.sha";
if ($version_from_fn && -f $version_from_fn &&
(my $git_version=qx(git rev-parse --short HEAD 2>$devnull)) && !$?) {
chomp($git_version);
tie(my @lines, 'Tie::File', $git_ref_fn) ||
die("error on Tie::File, $!");
@lines=($git_version)
unless @lines==1 && $lines[0] eq $git_version;
}
if ($git_ref_fn && -f $git_ref_fn) {
if ($mm_or->{'PM'}{$version_from_fn}) {
$mm_or->{'PM'}{$git_ref_fn}=$mm_or->{'PM'}{$version_from_fn}.'.sha';
}
elsif (grep {$version_from_fn eq $_} @{$mm_or->{'EXE_FILES'}}) {
(my $git_ref_base_fn=$git_ref_fn)=~s{^.*[/\\]}{};
$mm_or->{'PM'}{$git_ref_fn}='$(INST_SCRIPT)/'.$git_ref_base_fn;
}
}
# Done
#
return $post_initialize
}
# Construct a default Makefile macro prefix from an extension class
#
sub mm_prefix {
my $class=shift();
$class=~s/::/_/g;
return uc($class)
}
# Not used yet
#
sub special_targets {
my ($self, $mm_or, @param)=@_;
(my $section = (caller(0))[3]) =~ s/^.*:://;
msg("generating %s $section", ref($self));
my $special_targets=$self->{$section}($mm_or, @param);
$special_targets=~s/\.PHONY:\s+(.*)/\.PHONY: $1 cpanfile/m;
return $special_targets;
}
__END__
=begin markdown
# ASPEER::MakeMaker::MM::Import
## Name
ASPEER::MakeMaker::MM::Import - MakeMaker hook installer and active section implementations
## Synopsis
```perl
( run in 2.150 seconds using v1.01-cache-2.11-cpan-10df4c37326 )