• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

inc/H06-Oct-2011-3,4792,596

lib/App/local/lib/H06-Oct-2011-624286

maint/H06-Oct-2011-221143

script/H06-Oct-2011-12842

t/H06-Oct-2011-95

ChangesH A D06-Oct-20111.4 KiB3628

MANIFESTH A D06-Oct-2011760 3029

META.ymlH A D06-Oct-2011821 3534

Makefile.PLH A D10-Sep-2011549 3219

README.mkdnH A D06-Oct-20119.9 KiB241163

README.mkdn

1# NAME
2
3App::local::lib::helper - Make it easy to run code against a local-lib
4
5# SYNOPSIS
6
7Installing and using the helper (common usage)
8
9    cpanm --local-lib ~/mylib App::local::lib::helper
10    ~/mylib/bin/localenv bash
11
12Customizing the helper creation (advanced use only)
13
14    use App::local::lib::helper;
15    App::local::lib::helper->run(%opts);
16
17Note, if you don't have `cpanm` already installed you can use the web service
18version like so instead for all examples:
19
20    curl -L http://cpanmin.us/ | perl - --local-lib ~/mylib App::local::lib::helper
21
22# DESCRIPTION
23
24This is an object which provide the functionality to create a [local::lib](http://search.cpan.org/perldoc?local::lib)
25'helper' script in either the currently loaded [local::lib](http://search.cpan.org/perldoc?local::lib) environment or in
26a target directory of choice.  By default the script is called `localenv` and
27can be used to invoke a command under the [local::lib](http://search.cpan.org/perldoc?local::lib) which it was built
28against.  For example, assume you build a [local::lib](http://search.cpan.org/perldoc?local::lib) like so:
29
30    cpanm --local-lib ~/mylib App::local::lib::helper
31
32Note what is happening.  First, you are telling cpanminus to install everything
33to a local::lib directory called `~/mylib` (cpanminus behind the scenes uses
34[local::lib](http://search.cpan.org/perldoc?local::lib) to do this for you) then you are telling cpanminus to install the
35distribution [App::local::lib::helper](http://search.cpan.org/perldoc?App::local::lib::helper) into that created [local::lib](http://search.cpan.org/perldoc?local::lib) directory.
36When the `Makefile.PL` script for [App::local::lib::helper](http://search.cpan.org/perldoc?App::local::lib::helper) runs, it notices
37the fact that it is being asked to install into a locally lib managed directory
38and will additionally generate a helper script into `~/mylib/bin` called `localenv`.
39
40Now, if you want to invoke a perl application and use libs installed into
41`~/mylib`, you can do so like:
42
43    ~/mylib/bin/localenv perl [SOME COMMAND]
44
45The command `localenv` will make sure the same [local::lib](http://search.cpan.org/perldoc?local::lib) that was active
46when [App::local::lib::helper](http://search.cpan.org/perldoc?App::local::lib::helper) was originally installed is again installed
47into the environment before executing the commands passed in `@ARGV`.  Upon
48completing the command, the `%ENV` is restored so that you can use this to fire
49off an application against a specific [local::lib](http://search.cpan.org/perldoc?local::lib) without needing to deal
50with the details of how to activate the [local::lib](http://search.cpan.org/perldoc?local::lib) or how to make sure
51your `%ENV` stays clean.
52
53The arguments given to `localenv` don't need to be a perl application.  For
54example, I often like to open a sub shell under a particular [local::lib](http://search.cpan.org/perldoc?local::lib)
55managed directory.
56
57    ~/mylib/bin/localenv bash
58
59Now, if I do:
60
61    perl -V
62
63I'll see that i`~/mylib` has been added to `@INC`.  Additionally, `~/mylib/bin` will
64have been added to `$PATH`, so that any command line perl applications installed
65into the [local::lib](http://search.cpan.org/perldoc?local::lib) (such as `ack` or `cpanm`) can be accessed easily.
66
67Another example usage would be when you want to install an application from
68CPAN, install it and all its dependencies to a single directory root and
69then run it without a lot of effort.  For example:
70
71    cpanm --local-lib ~/gitalyst-libs Gitalist App::local::lib::helper
72    ~/gitalyst-libs/bin/localenv gitalyst-server.pl
73
74And presto! Your cpan installed application is running, fully self-contained to
75one root directory all under regular user privileges.
76
77[local::lib](http://search.cpan.org/perldoc?local::lib) does all the real work, but I find this to be the easiest way to
78run given code against a [local::lib](http://search.cpan.org/perldoc?local::lib) root.
79
80## Additional Helpers
81
82In addition to the `localenv` script which is documented above, we also create
83two snippets of code suitable for including in your `.bashrc` or `.cshrc`.
84These are created to help people that only want or need a single local lib and
85would like to activate it at login.  If you'd like to use these, simple add the
86following tot he end of your `.bashrc`
87
88    source $TARGET/bin/localenv-bashrc
89
90Where $TARGET is the root of your local lib (the directory that contains your
91`bin` and `lib` directories created when you ran the helper).
92
93Next time you log in, you can do `perl -V` and should see that your local-lib
94has automatically been activated.
95
96There will also be a `source $TARGET/bin/localenv-cshrc` created for those of
97you using csh.  Currently this is not going to work with Windows shell users,
98but should be easy to setup, collaborations very welcomed.
99
100# OPTIONS
101
102This class supports the following options.
103
104- which_perl
105
106This should be the path to the perl binary that the [local::lib](http://search.cpan.org/perldoc?local::lib) is built
107against. This defaults to the path of the perl binary under which we are
108currently running.  You should probably leave this one alone :)
109
110- target
111
112This is the target directory for the [local::lib](http://search.cpan.org/perldoc?local::lib) you want to build the helper
113script against.  By default it will attempt to detect the currently running
114[local::lib](http://search.cpan.org/perldoc?local::lib) and use that.  If we can't detect a running [local::lib](http://search.cpan.org/perldoc?local::lib) and
115this option is undef, we die with a message.
116
117- helper_name
118
119This is the name of the helper utility script.  It defaults to 'localenv'.
120
121- helper_permissions
122
123These are the permissions the the helper utility script is set to.  By default
124we set the equivilent of 'chmod 755 [HELPER SCRIPT]'
125
126# HELPERS
127
128This distribution installs the following [local::lib](http://search.cpan.org/perldoc?local::lib) helpers
129
130## localenv
131
132This is a perl script that runs a single command in [local::lib](http://search.cpan.org/perldoc?local::lib) aware context.
133You can use the `helper-name` option to set a different name.
134
135Typically I will use this to 'enable' a previously setup [local::lib](http://search.cpan.org/perldoc?local::lib) with
136commands like:
137
138    ~/mylocallib/bin/localenv bash
139    ~/mylocallib/bin/localenv screen
140
141Or I can use it to run a single command wrapped in the [local::lib](http://search.cpan.org/perldoc?local::lib) target
142and exit cleanly:
143
144    ~/mylocallib/bin/localenv perl app.pl
145    ~/mylocallib/bin/localenv plackup app.psgi
146
147## localenv-relative
148
149NOTE: Experimental feature.  Please prefer using [localenv](#pod_localenv) unless you
150absolutely need this functionality.
151
152This perl script functions (or should function) identically to [localenv](http://search.cpan.org/perldoc?localenv) as
153documented.  However, instead of having hardcoded full paths to your Perl
154binary and [local::lib](http://search.cpan.org/perldoc?local::lib) target directories, we instead try to use relative
155pathing.  For example, here is the helper script built on my server for the
156standard [localenv](#pod_localenv) script:
157
158    #!/Users/johnn/perl5/perlbrew/perls/perl-5.14.1/bin/perl
159
160    use strict;
161    use warnings;
162
163    use lib '/Users/johnn/locallib_5_14_1/lib/perl5';
164    use local::lib '/Users/johnn/locallib_5_14_1';
165
166    unless ( caller ) {
167        if ( @ARGV ) {
168            exec @ARGV;
169        }
170    }
171
172And here is the example same version for the relative script:
173
174    #!/usr/bin/env perl
175
176    use strict;
177    use warnings;
178
179    use FindBin;
180    use File::Spec;
181    use lib File::Spec->catdir($FindBin::Bin, '..', 'lib', 'perl5');
182    use local::lib File::Spec->catdir($FindBin::Bin, '..');
183
184    unless ( caller ) {
185        if ( @ARGV ) {
186            exec @ARGV;
187        }
188    }
189
190The goal here is to be more friendly when you need to relocate your
191installation of Perl and/or your [local::lib](http://search.cpan.org/perldoc?local::lib) target directory.  You might
192wish to try this if you are copying a 'seed' Perl and [local::lib](http://search.cpan.org/perldoc?local::lib) setup to
193multiple developer home directories (as a way to speed up first time developer
194setup, for example) or if your deployment system copies your application from
195your build enviroment to a QA or Production that is not identical.
196
197Personally I prefer to build Perl and my application in each location that is
198different, since I find that works very effectively.  However I understand some
199shops have existing build systems that deploy code by copying Perl dependencies
200from box to box, and these boxes are not always identical in directory layout.
201For example, there might be a build or integration point in development, with
202a [local::lib](http://search.cpan.org/perldoc?local::lib) target of `/home/integration/webapp-cpan-locallib` and you
203wish to copy that directory recursively to your qa/production server, which
204might be located at `/home/qa/local-lib`.
205
206I'd like to accomodate this approach as best I can, however I can't be certain
207that moving Perl and [local::lib](http://search.cpan.org/perldoc?local::lib) around rather than performing a true install
208is going to work consistently. Caveat emptor!
209
210Please also note that the following shell snippets are not relative tested.
211
212## localenv-bashrc
213
214a snippet suitable for sourcing in your .bashrc, which will automatically
215activate a local-lib at login.  Name will follow from `helper-name`.
216
217Here's an example of the line I might add to .bashrc (assumes you have setup
218[local::lib](http://search.cpan.org/perldoc?local::lib) in `$HOME/mylocal`
219
220    source $HOME/mylocal/localenv-bashrc
221
222Then next time you open a shell you should see that `$PATH` and `PERL5LIB`
223have been properly changed.
224
225## localenv-cshrc
226
227a snippet suitable for sourcing in your .cshrc, which will automatically
228activate a local-lib at login.  Name will follow from `helper-name`.
229
230
231
232# AUTHOR
233
234John Napiorkowski ` <<jjnapiork@cpan.org`> >
235
236# COPYRIGHT & LICENSE
237
238Copyright 2011, John Napiorkowski
239
240This program is free software; you can redistribute it and/or modify it under
241the same terms as Perl itself.