Last active
November 20, 2016 11:23
-
-
Save aero/e308b4c18b70e9cf2b02e7c74db2ade4 to your computer and use it in GitHub Desktop.
Automatically install all dependence modules through cpanminus within core Perl distribution.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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