NAME
FindLib - Helper to find libs to use in the filesystem tree
VERSION
Version 0.01
SYNOPSIS
#!/usr/bin/perl -w;
use strict;
## simple usage
use base FindLib '../mylib' => 'My::BootStrap';
## pass import parameters to your Bootstrap module
use base FindLib '../mylib' => 'My::Bootstrap', test => 1, dbi => 'sqlite';
## If you like verbose or if you don't have a Bootstrap module
use FindLib libs => [ 'lib', '../lib', 'devlib' ],
pkgs => { 'Test::More' => [ tests => 10 ],
'My::Module' => [ ],
};
DESCRIPTION
The purpose of this module is to replace
use FindBin;
use lib "$FindBin::Bin/../bootstrap/lib";
use My::Bootstrap %param;
with something shorter. This is specially useful if your project has a lot of scripts (For instance tests scripts).
use base FindLib '../bootstrap/lib' => 'My::Bootstrap', %param;
does exactly that without using FindBin module.
Note that the role of a Bootstrap module is actually to install more library paths in @INC
and to use more modules necessary to your application. It keeps your scripts nice and clean.
On the otherhand, if you don't want/need/have a Bootstrap module, you can still use FindLib to automatically identify the relative locations of your libraries and add them to your @INC
; just use the expanded version as seen in the SYNOPSIS.
DISCUSSION
Installation and availability of this module
The usefulness of this module is seriously reduced if FindLib is not already in your @INC / $ENV{PERL5LIB} -- Chicken and egg problem. This is the big disavantage of FindBin over FindLib: FindBin is distributed with Perl. To mitigate that, you need to be sure of global availability of the module in the system (You could install it via your favorite package managment system for intance).
modification of $0 and chdir (BEGIN blocks, other 'use')
As soon as FindLib is compiled it saves the location of the script and the initial cwd (current working directory), which are the two pieces of information the module relies on to interpret the relative path given by the calling program.
If cwd or $0 is changed before FindLib has a change to do its job, then FindLib will most probably die, saying "The script cannot be found". I don't know a workaround that. So be sure to load FindLib as soon as possible in your script to minimize problems (you are in control!).
(some programs alter $0 to customize the diplay line of the process in the system process-list (ps
on unix).
(Note, see perlvar for explanation of $0)
USAGE
import
All the work is done in import. So you need to 'use FindLib' and pass arguments to it.
Recognized arguments are:
libs
, a reference to a list of path to add to@INC
. The paths given are (should) be relative to the location of the current script. The paths won't be added unless the path actually exists on diskpkgs
, a reference to a hash containing package name as keys and arrayref of arguments (to import) as values.
The short forms implies that the first argument passed to import is not libs
or pkgs
. An example of usage is given in the SYNOPSIS section.
SEE ALSO
FindBin, FindBin::libs, lib, require, use
AUTHOR
Yann Kerherve, <yann.kerherve at gmail.com>
BUGS
Please report any bugs or feature requests to bug-find-lib at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FindLib. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
ACKNOWLEDGEMENT
Six Apart hackers nourrished the discussion that led to this module creation.
SUPPORT & CRITICS
I welcome feedback about this module, don't hesitate to contact me regarding this module, usage or code.
You can find documentation for this module with the perldoc command.
perldoc FindLib
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
RT: CPAN's request tracker
Search CPAN
COPYRIGHT & LICENSE
Copyright 2007 Yann Kerherve, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.