Skip to content

Instantly share code, notes, and snippets.

@aero
Last active November 20, 2016 11:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aero/e308b4c18b70e9cf2b02e7c74db2ade4 to your computer and use it in GitHub Desktop.
Save aero/e308b4c18b70e9cf2b02e7c74db2ade4 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 {
my @REQ_MODULES = qw/
Mojolicious
Text::CSV_XS
/;
require FindBin;
require lib;
my $locallib_path = "$FindBin::RealBin/locallib/$^V";
lib->import("$locallib_path/lib/perl5");
my @MISSING;
foreach my $module (@REQ_MODULES) {
unless (eval "require $module") {
push @MISSING, $module;
}
}
if (@MISSING) {
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;
open my $fh, '|-', "$^X - -v -n -l$locallib_path @MISSING";
print {$fh} $content;
close $fh;
lib->import("$locallib_path/lib/perl5");
}
}
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