Created
October 10, 2018 19:38
-
-
Save p120ph37/87499e15b1a2ad2df6ef89c5d55b3209 to your computer and use it in GitHub Desktop.
This file contains 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
### | |
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