Skip to content

Instantly share code, notes, and snippets.

@aero aero/autoinstall2.pl
Last active Nov 20, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.