-
Notifications
You must be signed in to change notification settings - Fork 36
/
cpan-install
executable file
·82 lines (61 loc) · 2.17 KB
/
cpan-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env perl
# vim: set filetype=perl:
# env is a perl script similar in concept to /usr/bin/env
# If you have a local-lib5 directory then this script will set it up for
# you as it executes.
# If used like /usr/bin/env then it will run other commands based on
# your current path settings (with a local::lib environment if present)
#
# e.g. script/env bash
#
# NOTE: This environment _IS NOT_ self contained
# If included inside another perl script, then it will be a no-op if
# a local::lib environment is not present, but if one is, it will be
# used as a --self-contained environment, expected to contain all non-core
# dependencies for your perl
#
# e.g.
# use FindBin;
# BEGIN { do "$FindBin::Bin/env" or die $@ }
# The local::lib behavior can be explicitly enabled or disabled by setting
# the CATALYST_LOCAL_LIB enviromnent variable to true or false.
use strict;
use warnings;
use Carp;
use lib;
use FindBin;
use File::Spec ();
use Cwd ();
use CPAN 'install';
# Look up to see find Makefile.PL aka the base of the local::lib install.
my $lookup; $lookup = sub {
my $dir = $_[0] || $FindBin::Bin;
return '' if Cwd::abs_path($dir) eq File::Spec->rootdir;
my $tryfile = File::Spec->catfile($dir, "Makefile.PL");
return -r $tryfile ? $dir : $lookup->( File::Spec->catdir($dir, File::Spec->updir) );
};
my $basedir = $lookup->();
$basedir ||= '';
my $target = "$basedir/local-lib5";
my $on = -d $target;
$on = ! ! $ENV{CATALYST_LOCAL_LIB}
if (exists $ENV{CATALYST_LOCAL_LIB} and defined $ENV{CATALYST_LOCAL_LIB});
Carp::confess("Could not find local-lib5 from '$FindBin::Bin'")
if ($on && ! length $basedir);
if ( $on ) {
# So we can find local::lib when fully self contained
lib->import("$target/lib/perl5");
# . for CPAN + app dir
my @include = ('.', "$basedir/lib");
$ENV{PERL5LIB} = join ':', @include;
# Sorry kane ;)
$ENV{PERL_AUTOINSTALL_PREFER_CPAN}=1;
$ENV{PERL_MM_OPT} .= " INSTALLMAN1DIR=none INSTALLMAN3DIR=none";
require lib::core::only;
require local::lib;
lib::core::only->import();
local::lib->import( $target );
install $_ for @ARGV;
} else {
die "No local::lib configured.";
}