Bump version to 0.003006, update Changes and README.
[catagits/Gitalist.git] / script / cpan-install
CommitLineData
cc2551d8 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
28use strict;
29use warnings;
30use Carp;
31use lib;
32use FindBin;
33use File::Spec ();
34use Cwd ();
35use CPAN 'install';
36
37# Look up to see find Makefile.PL aka the base of the local::lib install.
38my $lookup; $lookup = sub {
39 my $dir = $_[0] || $FindBin::Bin;
40
41 return '' if Cwd::abs_path($dir) eq File::Spec->rootdir;
42
43 my $tryfile = File::Spec->catfile($dir, "Makefile.PL");
44
45 return -r $tryfile ? $dir : $lookup->( File::Spec->catdir($dir, File::Spec->updir) );
46};
47
48my $basedir = $lookup->();
49
50$basedir ||= '';
51my $target = "$basedir/local-lib5";
52
53my $on = -d $target;
54$on = ! ! $ENV{CATALYST_LOCAL_LIB}
55 if (exists $ENV{CATALYST_LOCAL_LIB} and defined $ENV{CATALYST_LOCAL_LIB});
56
57Carp::confess("Could not find local-lib5 from '$FindBin::Bin'")
58 if ($on && ! length $basedir);
59
60if ( $on ) {
61 # So we can find local::lib when fully self contained
62 lib->import("$target/lib/perl5");
63
64 # . for CPAN + app dir
65 my @include = ('.', "$basedir/lib");
66
67 $ENV{PERL5LIB} = join ':', @include;
68
69 # Sorry kane ;)
70 $ENV{PERL_AUTOINSTALL_PREFER_CPAN}=1;
71
72 $ENV{PERL_MM_OPT} .= " INSTALLMAN1DIR=none INSTALLMAN3DIR=none";
73
74 require lib::core::only;
75 require local::lib;
76 lib::core::only->import();
77 local::lib->import( $target );
78
79 install $_ for @ARGV;
80} else {
81 die "No local::lib configured.";
82}