-
-
24 Jan 2020 10:39:38 UTC
- Distribution: lib-abs
- Module version: 0.95
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues (4)
- Testers (1812 / 16 / 0)
- Kwalitee
Bus factor: 1- 80.56% Coverage
- License: perl_5
- Perl: v5.6.0
- Activity
24 month- Tools
- Download (40.62KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors- -2020 by Mons Anderson.
- Dependencies
- Cwd
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
lib::abs -
lib
that makes relative path absolute to caller.SYNOPSIS
Simple use like
use lib ...
:use lib::abs qw(./mylibs1 ../mylibs2); use lib::abs 'mylibs'; # if your path may not exists and it is ok, then: use lib::abs -soft => qw(./mylibs1 ../mylibs2);
Extended syntax (glob)
use lib::abs 'modules/*/lib';
There are also may be used helper function from lib::abs (see example/ex4):
use lib::abs; # ... my $path = lib::abs::path('../path/relative/to/me'); # returns absolute path
DESCRIPTION
The main reason of this library is transformate relative paths to absolute at the
BEGIN
stage, and push transformed to@INC
. Relative path basis is not the current working directory, but the location of file, where the statement is (caller file). When using commonlib
, relative paths stays relative to curernt working directory,# For ex: # script: /opt/scripts/my.pl use lib::abs '../lib'; # We run `/opt/scripts/my.pl` having cwd /home/mons # The @INC will contain '/opt/lib'; # We run `./my.pl` having cwd /opt # The @INC will contain '/opt/lib'; # We run `../my.pl` having cwd /opt/lib # The @INC will contain '/opt/lib';
Also this module is useful when writing tests, when you want to load strictly the module from ../lib, respecting the test file.
# t/00-test.t use lib::abs '../lib';
Also this is useful, when you running under
mod_perl
, use something likeApache::StatINC
, and your application may change working directory. So in case of chdirStatINC
fails to reload module if the @INC contain relative paths.RATIONALE
Q: We already have
FindBin
andlib
, why we need this module?A: There are several reasons:
- 1)
FindBin
could find path incorrectly undermod_perl
- 2)
FindBin
works relatively to executed binary instead of relatively to caller - 3) Perl is linguistic language, and
`use lib::abs "..."'
semantically more clear and looks more beautiful than`use FindBin; use lib "$FindBin::Bin/../lib";'
- 4)
FindBin
b<will> work incorrectly, if will be called not from executed binary (see http://github.com/Mons/lib-abs-vs-findbin comparison for details)
BUGS
None known
COPYRIGHT AND LICENSE
This software is copyright (c) 2007-2020 by Mons Anderson.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
AUTHOR
Mons Anderson,
<mons@cpan.org>
CONTRIBUTORS
Oleg Kostyuk,
<cub@cpan.org>
Module Install Instructions
To install lib::abs, copy and paste the appropriate command in to your terminal.
cpanm lib::abs
perl -MCPAN -e shell install lib::abs
For more information on module installation, please visit the detailed CPAN module installation guide.