Skip to content

Instantly share code, notes, and snippets.

@aero
Last active November 20, 2016 11:24
Show Gist options
  • Save aero/b31df2de10c47c7c99ee0d4f4cd5ec7a to your computer and use it in GitHub Desktop.
Save aero/b31df2de10c47c7c99ee0d4f4cd5ec7a to your computer and use it in GitHub Desktop.
Automatically install all dependence modules through cpanminus within core Perl distribution.
#!/usr/bin/env perl
BEGIN {
require FindBin;
require lib;
my $locallib_path = "$FindBin::RealBin/locallib/$^V";
lib->import("$locallib_path/lib/perl5");
my $cpanm;
my $get_cpanm = sub {
return $cpanm if defined $cpanm;
require IO::Socket;
my $s = IO::Socket::INET->new(PeerAddr => 'cpanmin.us:80') or die $!;
print {$s} "GET / HTTP/1.1\r\nHost: cpanmin.us\r\n\r\n";
my $content;
while (<$s>) { last if m/^\r\n$/; }
while (<$s>) { $content .= $_; last if m/^__END__$/; }
close $s;
return $content;
};
push @INC, sub {
my $file = $_[1];
my $module = $file;
return if grep { $file eq $_ } qw{
Encode/ConfigLocal.pm
Devel/StackTraceFrame.pm
Log/Agent.pm
};# from lib::xi module
print "Oops: There was an error looking for $module\n";
$module =~ s/\.pm \z//xms;
$module =~ s{/}{::}xmsg;
$cpanm = $get_cpanm->();
open my $fh, '|-', "$^X - -v -n -l$locallib_path $module";
print {$fh} $cpanm;
close $fh;
lib->import("$locallib_path/lib/perl5");
require Config;
Config->import;
my @myinc = (
"$locallib_path/lib/perl5",
"$locallib_path/lib/perl5/$Config::Config{archname}"
);
foreach my $lib (grep {defined} @myinc) {
if(open my $inh, '<', "$lib/$file") {
$INC{$file} = "$lib/$file";
return $inh;
}
}
return;
};
}
use strict;
use warnings;
use Mojolicious;
use Text::CSV_XS;
print "$^V\n";
print "$_\n" for @INC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment