Skip to content

Instantly share code, notes, and snippets.

@aero aero/autoinstall.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 {
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
You can’t perform that action at this time.