ASPEER-MakeMaker
view release on metacpan or search on metacpan
lib/ASPEER/MakeMaker/MM/Import.pm view on Meta::CPAN
# Sections to augment with additional targets
#
{ no warnings qw(redefine once);
foreach my $section (qw(const_config depend postamble post_initialize), @section) {
next if $self{$section};
$self{$section} =*{"ExtUtils::MM::${section}"}{CODE}; # unless (*{"ExtUtils::MM::${section}"}{CODE} eq \&{$section});
$self{$section} ||= do {
my ($cr)=grep {$_} (map { $_->can($section) } @mm_isa);
$cr || sub {''};
};
$self{$section} ||= ExtUtils::MM_Unix->can($section) || sub {''};
my $sub=sprintf('%s::MM::%s', ref($self), $section);
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;
lib/ASPEER/MakeMaker/MM/Import.pm view on Meta::CPAN
use ASPEER::MakeMaker;
```
```perl
use ASPEER::MakeMaker qw(const_config postamble);
```
Usually this module is not used directly. It is loaded by
`ASPEER::MakeMaker::import`.
## Description
`ASPEER::MakeMaker::MM::Import` installs and implements the current
`ExtUtils::MakeMaker` hooks for this distribution.
It only performs hook installation while running under a `Makefile.PL` process.
If imported outside that context, it returns without modifying `ExtUtils::MM`.
The module always considers `const_config`, `depend`, `postamble`, and
`post_initialize`, and also honors any additional section names passed by the
caller. For each section, it saves the original MakeMaker implementation and
then replaces `ExtUtils::MM::$section` with a wrapper.
If a method named `<importing class>::MM::<section>` exists, the wrapper calls
that method. Otherwise it calls the section method implemented in this module.
## Import Behavior
```perl
ASPEER::MakeMaker::MM::Import->import(@sections);
```
The import process:
1. Returns immediately if this class has already been loaded.
2. Returns immediately unless the current process name matches `Makefile.PL`.
3. Builds a list of active `ExtUtils::MM::*` classes from `@ExtUtils::MM::ISA`.
4. Saves the original implementation for each requested section.
5. Replaces the matching `ExtUtils::MM::*` symbol with a wrapper.
The original method is stored in the hook object's internal hash and is called
by the replacement section methods before augmenting the result.
The importing class and requested section names are also recorded in activation
order. Generated `PERLRUN` commands use this registry so chained extensions are
reloaded once each and in the same order.
## Section Methods
### const_config
```perl
ASPEER::MakeMaker::MM::Import::const_config($hook, $mm, @args);
```
Calls the original MakeMaker `const_config`, then copies constants from
`ASPEER::MakeMaker::MM::Constant` into the Makefile macro table.
`MM_PREFIX` is private hook configuration and is not emitted as a Makefile
macro.
It publishes supplied license metadata:
- copies `LICENSE` and the first `AUTHOR` into the macro table when supplied
- uses `Software::LicenseUtils` to resolve the license when both are supplied
- writes the resulting URL into `META_MERGE.resources.license`
Neither `LICENSE` nor `AUTHOR` is required by this helper.
The method then installs a global `PERLRUN` command which preserves loaded
MakeMaker extensions and local include paths. Include arguments are quoted
through the active MakeMaker implementation. It also stores `DIST_DEFAULT` in
the `DIST_DEFAULT_TARGET` macro.
### depend
```perl
ASPEER::MakeMaker::MM::Import::depend($hook, $mm, @args);
```
Calls the original MakeMaker `depend` section. When `VERSION_FROM` is set, it
appends the following dependency unless it is already present:
```make
Makefile : $(VERSION_FROM)
```
### postamble
```perl
ASPEER::MakeMaker::MM::Import::postamble($hook, $mm, @args);
```
Calls the original MakeMaker `postamble`, then appends the template named by
`TEMPLATE_POSTAMBLE_FN` in the importing class's `MM::Constant` package.
The module uses `MM_PREFIX` from the importing class's `MM::Constant` package
when naming its command macro. If it is absent, the class name is uppercased
and `::` is replaced with `_`. MakeMaker's `oneliner` method generates the
platform-specific Perl command. The command deliberately uses the global
`PERLRUN` macro so the same extension environment is available to generated
targets, then explicitly reloads the dispatch module belonging to this prefix.
This keeps the target callable when a subsequently loaded extension replaces
the shared `PERLRUN` value.
The parent class's bundled template is:
```text
lib/ASPEER/MakeMaker/MM/postamble.inc
```
### post_initialize
```perl
ASPEER::MakeMaker::MM::Import::post_initialize($hook, $mm, @args);
```
Calls the original MakeMaker `post_initialize` section, then:
- installs `LICENSE` when it exists
- excludes `.md`, `.xml`, `.pod`, `.bak`, `.tmp`, `.new`, `.old`, `.ref`,
`.0`, and `.1` sources from the install map
lib/ASPEER/MakeMaker/MM/Import.pm view on Meta::CPAN
If a method named C<<< <importing class>::MM::<section> >>> exists, the wrapper calls
that method. Otherwise it calls the section method implemented in this module.
=head2 Import Behavior
ASPEER::MakeMaker::MM::Import->import(@sections);
The import process:
=over
=item 1.
Returns immediately if this class has already been loaded.
=item 2.
Returns immediately unless the current process name matches C<Makefile.PL>.
=item 3.
Builds a list of active C<ExtUtils::MM::*> classes from C<@ExtUtils::MM::ISA>.
=item 4.
Saves the original implementation for each requested section.
=item 5.
Replaces the matching C<ExtUtils::MM::*> symbol with a wrapper.
=back
The original method is stored in the hook object's internal hash and is called
by the replacement section methods before augmenting the result.
The importing class and requested section names are also recorded in activation
order. Generated C<PERLRUN> commands use this registry so chained extensions are
reloaded once each and in the same order.
=head2 Section Methods
=head3 const_config
ASPEER::MakeMaker::MM::Import::const_config($hook, $mm, @args);
Calls the original MakeMaker C<const_config>, then copies constants from
C<ASPEER::MakeMaker::MM::Constant> into the Makefile macro table.
C<MM_PREFIX> is private hook configuration and is not emitted as a Makefile
macro.
It publishes supplied license metadata:
=over
=item -
copies C<LICENSE> and the first C<AUTHOR> into the macro table when supplied
=item -
uses C<Software::LicenseUtils> to resolve the license when both are supplied
=item -
writes the resulting URL into C<META_MERGE.resources.license>
=back
Neither C<LICENSE> nor C<AUTHOR> is required by this helper.
The method then installs a global C<PERLRUN> command which preserves loaded
MakeMaker extensions and local include paths. Include arguments are quoted
through the active MakeMaker implementation. It also stores C<DIST_DEFAULT> in
the C<DIST_DEFAULT_TARGET> macro.
=head3 depend
ASPEER::MakeMaker::MM::Import::depend($hook, $mm, @args);
Calls the original MakeMaker C<depend> section. When C<VERSION_FROM> is set, it
appends the following dependency unless it is already present:
Makefile : $(VERSION_FROM)
=head3 postamble
ASPEER::MakeMaker::MM::Import::postamble($hook, $mm, @args);
Calls the original MakeMaker C<postamble>, then appends the template named by
C<TEMPLATE_POSTAMBLE_FN> in the importing class's C<MM::Constant> package.
The module uses C<MM_PREFIX> from the importing class's C<MM::Constant> package
when naming its command macro. If it is absent, the class name is uppercased
and C<::> is replaced with C<_>. MakeMaker's C<oneliner> method generates the
platform-specific Perl command. The command deliberately uses the global
C<PERLRUN> macro so the same extension environment is available to generated
targets, then explicitly reloads the dispatch module belonging to this prefix.
This keeps the target callable when a subsequently loaded extension replaces
the shared C<PERLRUN> value.
The parent class's bundled template is:
lib/ASPEER/MakeMaker/MM/postamble.inc
=head3 post_initialize
( run in 1.565 second using v1.01-cache-2.11-cpan-16aabcbfbcb )