Alt-Math-Prime-FastSieve-Inline

 view release on metacpan or  search on metacpan

inc/Inline/Module.pm  view on Meta::CPAN

    for my $module (@$stub_modules) {
        my $code = $class->dyna_module($module);
        $class->write_module("$distdir/lib", $module, $code);
        $code = $class->proxy_module($module);
        $class->write_module("$distdir/inc", $module, $code);
        $module =~ s!::!/!g;
        push @$manifest, "lib/$module.pm"
            unless -e "lib/$module.pm";
        push @$manifest, "inc/$module.pm";
    }
    for my $module (@$included_modules) {
        my $code = $module eq 'Inline::CPP::Config'
        ? $class->read_share_cpp_config
        : $class->read_local_module($module);
        $class->write_module("$distdir/inc", $module, $code);
        $module =~ s!::!/!g;
        push @$manifest, "inc/$module.pm";
    }

    $class->add_to_manifest($distdir, @$manifest);

    return $manifest; # return a list of the files added
}

sub make_stub_modules {
    my ($class, @modules) = @_;

    for my $module (@modules) {
        my $code = $class->proxy_module($module);
        my $path = $class->write_module('lib', $module, $code, 'onchange');
        if ($path) {
            print "Created stub module '$path' (Inline::Module $VERSION)\n";
        }
    }
}

sub read_local_module {
    my ($class, $module) = @_;
    eval "require $module; 1" or die $@;
    my $file = $module;
    $file =~ s!::!/!g;
    $class->read_file($INC{"$file.pm"});
}

sub read_share_cpp_config {
    my ($class) = @_;
    require File::Share;
    my $dir = File::Share::dist_dir('Inline-Module');
    my $path = File::Spec->catfile($dir, 'CPPConfig.pm');
    $class->read_file($path);
}

sub proxy_module {
    my ($class, $module) = @_;

    return <<"...";
# DO NOT EDIT. GENERATED BY: Inline::Module
#
# This module is for author-side development only. When this module is shipped
# to CPAN, it will be automagically replaced with content that does not
# require any Inline framework modules (or any other non-core modules).
#
# To regenerate this stub module, run this command:
#
#   perl -MInline::Module=makestub,$module

use strict; use warnings;
package $module;
use Inline::Module stub => '$API_VERSION';
1;
...
}

sub dyna_module {
    my ($class, $module) = @_;
    return <<"...";
# DO NOT EDIT. GENERATED BY: Inline::Module $Inline::Module::VERSION

use strict; use warnings;
package $module;
use base 'DynaLoader';
bootstrap $module;
1;
...

# TODO: Add XS VERSION checking support:
# our \$VERSION = '0.0.5';
# bootstrap $module \$VERSION;
}

sub read_file {
    my ($class, $filepath) = @_;
    open IN, '<', $filepath
        or die "Can't open '$filepath' for input:\n$!";
    my $code = do {local $/; <IN>};
    close IN;
    return $code;
}

sub write_module {
    my ($class, $dest, $module, $code, $onchange) = @_;
    $onchange ||= 0;

    $code =~ s/\n+__END__\n.*//s;

    my $filepath = $module;
    $filepath =~ s!::!/!g;
    $filepath = "$dest/$filepath.pm";
    my $dirpath = $filepath;
    $dirpath =~ s!(.*)/.*!$1!;
    File::Path::mkpath($dirpath);

    return if $onchange and
        -e $filepath and
        $class->read_file($filepath) eq $code;

    unlink $filepath;
    open OUT, '>', $filepath
        or die "Can't open '$filepath' for output:\n$!";
    print OUT $code;
    close OUT;



( run in 1.222 second using v1.01-cache-2.11-cpan-e1769b4cff6 )