ASPEER-MakeMaker

 view release on metacpan or  search on metacpan

cpanfile  view on Meta::CPAN

requires 'FindBin';
requires 'IO::File';
requires 'Software::LicenseUtils';
requires 'Tie::File';
requires 'base';
requires 'perl', '5.008';
requires 'strict';
requires 'vars';
requires 'warnings';

on configure => sub {
    requires 'perl', '5.008';
    requires 'ExtUtils::MakeMaker';
    requires 'Tie::File';
    requires 'version';
    suggests 'ASPEER::MakeMaker::Markdown::Pod', '1.010';
};

on test => sub {
    requires 'File::Path';
    requires 'File::Temp';
    requires 'Test::More';
};

lib/ASPEER/MakeMaker.pm  view on Meta::CPAN

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");

lib/ASPEER/MakeMaker/MM/Import.pm  view on Meta::CPAN



#  All done, init finished
#
1;


#======================================================================================================================


sub import {


    #  Manage activation of various ExtUtils::Makemaker sections for this class.
    #
    #  use ExtUtils::<This Package> qw(const_config) to just replace the macros section of the Makefile
    #  .. qw(dist_ci) to replace standard MakeMaker targets with our own
    #  .. qw(:all) or no tag (i.e defaults) to all targers
    #
    #
    my ($class, @section)=@_;

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));


lib/ASPEER/MakeMaker/MM/Import.pm  view on Meta::CPAN

    #
    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

lib/ASPEER/MakeMaker/MM/Import.pm  view on Meta::CPAN

        $depend.=$/ if length($depend) && substr($depend, -1) ne $/;
        $depend.='Makefile : $(VERSION_FROM)'.$/;
    }
    return $depend;

}


#  MakeMaker::MY replacement postamble section
#
sub postamble {


    #  Get self ref
    #
    my ($self, $mm_or, @param)=@_;
    (my $section = (caller(0))[3]) =~ s/^.*:://;
    msg("generating %s $section", ref($self));


    #  Get original postamble ready for append

lib/ASPEER/MakeMaker/MM/Import.pm  view on Meta::CPAN

    }


    #  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

lib/ASPEER/MakeMaker/MM/Import.pm  view on Meta::CPAN


    #  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;

}

lib/ASPEER/MakeMaker/MM/Util.pm  view on Meta::CPAN

($Carp::Verbose=++$DEBUG) if $ENV{uc("${Script}_DEBUG")};


#  Done
#
1;

#==================================================================================================


sub quiet_enable {


    #  Turn on quiet flag
    #
    $QUIET=shift() || 1;


}


sub verbose {

    #  Print verbose message
    #
    return if $QUIET || !$VERBOSE;
    return CORE::print STDERR &fmt(@_), $/;

}


sub verbose_enable {

    #  Turn on verbose flag
    #
    $VERBOSE=shift() || 1;

}


sub debug_enable {

    #  Turn on debugging flag
    #
    $DEBUG=shift();

}


sub debug {

    #  Debug
    #
    $DEBUG || return;
    my $debug=sprintf(shift(), @_);
    chomp($debug);
    my ($package, undef, $line, $method) = caller(1);  # '1' for caller of the function
    print STDERR sprintf("[%s:%d] %s$/",
        join('::', grep {$_} ($package, $method)),
        $line,
        $debug
    );

}


sub err {

    #  Quit on errors
    #
    my $msg=&fmt('error: %s', @_);
    CORE::print STDERR $msg, "\n";
    eval {require Carp; 1};
    Carp::croak;

}


sub fmt {


    #  Format message nicely. Always called by err or msg so caller=2
    #
    my $message=sprintf(shift(), @_);
    chomp($message);
    my @caller=(caller(2));
    my $caller=$caller[3] || $caller[0];
    my ($class, $method)=($caller=~/^(.*)::([^:]+)$/);
    $method ||=$caller[0];
    $caller=~s/^_?!(_)//;
    my $format=' @<<<<<<<<<<<<<<<<<< @*';
    local $^A='';
    formline $format, "[$method]", $message;
    return $^A;

}


sub msg {

    #  Print message
    #
    return (CORE::print STDERR &fmt(@_), $/) unless $QUIET;

}


sub slurp {

    #  Slurp in file content
    #
    my ($fn)=@_;
    my $fh=IO::File->new($fn, 'r') ||
        return err("unable to open file $fn, $!");
    local $/=undef;
    my $text=<$fh>;
    $fh->close();
    return $text || '';

}


sub blurp {

    #  Save file content
    #
    my ($fn, $text)=@_;
    my $fh=IO::File->new($fn, 'w') ||
        return err("unable to open $fn for write, $!");
    $fh->print($text) ||
        return err("unable to write file $fn, $!");
    $fh->close() ||
        return err("unable to close file $fn, $!");
    return 1;

}


sub touch {

    my ($fn)=@_;
    return 1 if -e $fn;
    return blurp($fn, '');

}


sub perlrun {


    #  Get self ref
    #
    my ($self, $mm_or)=@_;


    #  Construct PERL runtime
    #
    my $perl_inc_ar=&perl_inc;

lib/ASPEER/MakeMaker/MM/Util.pm  view on Meta::CPAN

    $perlrun="\$(PERL) $perlrun_inc $perlrun_mod";


    #  And return
    #
    return $perlrun

}


sub perl_mod {

    my %seen=(
        __PACKAGE__ => 1
    );
    my @m=sort
        grep { !$seen{$_}++ }
        map {(my $m = $_) =~ s{\.pm$}{}; $m =~ s{/}{::}g; $m;}
        grep { m{^ExtUtils/} }
        keys %INC;
    return \@m;
}


sub perl_inc {

    #  Return array ref of any additional libraries specified via command line (-I)
    #
    my %default_inc=map { $_ => 1 } @{ perl_inc_default() || [] };
    my %seen;
    my @lib=grep {
        !$default_inc{$_} && !$seen{$_}++
    } map {
        File::Spec->rel2abs($_)
    } grep {
        defined($_) && !ref($_) && length($_) && -d $_
    } @INC;

    return \@lib;
}


sub perl_inc_default {

    my @default_inc;
    if (open(my $perl_fh, '-|', $^X, '-e', 'print join qq(\0), grep { defined && !ref && length && -d } @INC')) {
        local $/;
        my $inc=<$perl_fh>;
        close($perl_fh);
        @default_inc=map {
            File::Spec->rel2abs($_)
        } split(/\0/, ($inc || ''));
    }
    return \@default_inc;
}


sub arg {

    #  Convert MakeMaker target args to a named parameter hash.
    #
    my (%param, @argv);
    (@param{qw(
        NAME
        NAME_SYM
        DISTNAME
        DISTVNAME
        VERSION

t/02-mm-integration.t  view on Meta::CPAN

use Cwd qw(abs_path getcwd);
use File::Path qw(make_path);
use File::Temp qw(tempdir);
use Test::More qw(no_plan);

use ASPEER::MakeMaker::MM::Util ();


#  Read and write test fixture files
#
sub slurp {

    my ($fn)=@_;
    open(my $input_fh, '<', $fn) || die("unable to open $fn, $!");
    local $/=undef;
    my $text=<$input_fh>;
    close($input_fh) || die("unable to close $fn, $!");
    return $text;

}


sub blurp_test {

    my ($fn, $text)=@_;
    open(my $output_fh, '>', $fn) || die("unable to open $fn, $!");
    print $output_fh $text;
    close($output_fh) || die("unable to close $fn, $!");
    return 1;

}


t/02-mm-integration.t  view on Meta::CPAN

    'Makefile.PL succeeds without VERSION_FROM');
ok(!-e '.sha', 'Git-SHA provenance is not created without VERSION_FROM');

chdir($cwd) || die("unable to chdir $cwd, $!");


#  File writes must report both data and close failures
#
{
    no warnings qw(redefine);
    local *IO::File::new=sub {bless({}, 'Local::FailingWrite')};
    my $write_ok=eval {
        ASPEER::MakeMaker::MM::Util::blurp('ignored', 'text');
        1;
    };
    ok(!$write_ok, 'file write failure is fatal');
}
{
    no warnings qw(redefine);
    local *IO::File::new=sub {bless({}, 'Local::FailingClose')};
    my $close_ok=eval {
        ASPEER::MakeMaker::MM::Util::blurp('ignored', 'text');
        1;
    };
    ok(!$close_ok, 'file close failure is fatal');
}


package Local::FailingWrite;

sub print {return 0}
sub close {return 1}


package Local::FailingClose;

sub print {return 1}
sub close {return 0}

t/ASPEER-MakeMaker.t  view on Meta::CPAN

    $version_from_fn,
    'perl',
    'Andrew Speer <aspeer@localdomain>',
    $dest_fn,
    '',
    'all',
    '.pm',
    'lib/ASPEER/MakeMaker.pm',
);

sub target_args {
    my ($to_inst_pm, @argv)=@_;
    my @args=@makemaker_args;
    $args[9]=$to_inst_pm;
    return (@args, @argv);
}

my $postamble=do {
    open(my $fh, '<', $TEMPLATE_POSTAMBLE_FN)
        or die "unable to open $TEMPLATE_POSTAMBLE_FN: $!";
    local $/;



( run in 3.006 seconds using v1.01-cache-2.11-cpan-0e0213f3164 )