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