From: Dan Brook Date: Sat, 26 Feb 2011 15:15:48 +0000 (+0000) Subject: Add cpan-install utility script. X-Git-Tag: 0.002008~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FGitalist.git;a=commitdiff_plain;h=cc2551d80c9d8bf8ae9d9309b68589a58ecaa285 Add cpan-install utility script. This utility script should prove useful to anyone running from a Gitalist clone. It will allows you to install additional modules into local-lib5 which can be tricky to do otherwise e.g "./script/env cpanm Module" doesn't work if Module is already installed outside the local-lib5. --- diff --git a/script/cpan-install b/script/cpan-install new file mode 100755 index 0000000..a573681 --- /dev/null +++ b/script/cpan-install @@ -0,0 +1,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."; +}