1lib::abs(3)           User Contributed Perl Documentation          lib::abs(3)
2
3
4

NAME

6       lib::abs - "lib" that makes relative path absolute to caller.
7

SYNOPSIS

9       Simple use like "use lib ...":
10
11               use lib::abs qw(./mylibs1 ../mylibs2);
12               use lib::abs 'mylibs';
13
14               # if your path may not exists and it is ok, then:
15               use lib::abs -soft => qw(./mylibs1 ../mylibs2);
16
17       Extended syntax (glob)
18
19               use lib::abs 'modules/*/lib';
20
21       There are also may be used helper function from lib::abs (see
22       example/ex4):
23
24               use lib::abs;
25               # ...
26               my $path = lib::abs::path('../path/relative/to/me'); # returns absolute path
27

DESCRIPTION

29       The main reason of this library is transformate relative paths to
30       absolute at the "BEGIN" stage, and push transformed to @INC.  Relative
31       path basis is not the current working directory, but the location of
32       file, where the statement is (caller file).  When using common "lib",
33       relative paths stays relative to curernt working directory,
34
35               # For ex:
36               # script: /opt/scripts/my.pl
37               use lib::abs '../lib';
38
39               # We run `/opt/scripts/my.pl` having cwd /home/mons
40               # The @INC will contain '/opt/lib';
41
42               # We run `./my.pl` having cwd /opt
43               # The @INC will contain '/opt/lib';
44
45               # We run `../my.pl` having cwd /opt/lib
46               # The @INC will contain '/opt/lib';
47
48       Also this module is useful when writing tests, when you want to load
49       strictly the module from ../lib, respecting the test file.
50
51               # t/00-test.t
52               use lib::abs '../lib';
53
54       Also this is useful, when you running under "mod_perl", use something
55       like "Apache::StatINC", and your application may change working
56       directory.  So in case of chdir "StatINC" fails to reload module if the
57       @INC contain relative paths.
58

RATIONALE

60       Q: We already have "FindBin" and "lib", why we need this module?
61
62       A: There are several reasons:
63
64       1) "FindBin" could find path incorrectly under "mod_perl"
65       2) "FindBin" works relatively to executed binary instead of relatively
66       to caller
67       3) Perl is linguistic language, and `use lib::abs "..."' semantically
68       more clear and looks more beautiful than `use FindBin; use lib
69       "$FindBin::Bin/../lib";'
70       4) "FindBin" b<will> work incorrectly, if will be called not from
71       executed binary (see <http://github.com/Mons/lib-abs-vs-findbin>
72       comparison for details)
73

BUGS

75       None known
76
78       This software is copyright (c) 2007-2020 by Mons Anderson.
79
80       This is free software; you can redistribute it and/or modify it under
81       the same terms as the Perl 5 programming language system itself.
82

AUTHOR

84       Mons Anderson, "<mons@cpan.org>"
85

CONTRIBUTORS

87       Oleg Kostyuk, "<cub@cpan.org>"
88
89
90
91perl v5.32.0                      2020-07-28                       lib::abs(3)
Impressum