Skip to content

Instantly share code, notes, and snippets.

@p120ph37
Created October 10, 2018 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p120ph37/87499e15b1a2ad2df6ef89c5d55b3209 to your computer and use it in GitHub Desktop.
Save p120ph37/87499e15b1a2ad2df6ef89c5d55b3209 to your computer and use it in GitHub Desktop.
###
package autodeps;
###
use strict;
use warnings;
use Cwd qw/cwd abs_path/;
use File::Basename qw/dirname/;
use File::Spec::Functions qw/catdir/;
our $local = catdir(abs_path(dirname(__FILE__)), 'local');
sub import {
my @r = map{ my $r = "$_.pm"; $r =~ s/::/\//g; $r; }(@_[1..$#_]);
eval {
require(catdir($local, qw/lib perl5 local lib.pm/));
local::lib->import($local);
require $_ for @r;
};
if($@) {
open my $oldout, '>&', \*STDOUT;
open \*STDOUT, '>&', \*STDERR;
my $cwd = cwd();
chdir catdir($local, '..');
system(qw/cpanm -l local local::lib/, @_[1..$#_]);
warn "CWD: $cwd\n";
chdir $cwd;
require(catdir($local, qw/lib perl5 local lib.pm/));
local::lib->import($local);
require $_ for @r;
open \*STDOUT, '>&', $oldout;
}
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment