I was reading the code of "blib.pm" and thinking why it is written that way. Why using "Cwd" when relative paths work perfectly?
The implementation of "blib" does something similar to this:
sub import { my $blib = abs_path('blib/lib'); push @INC, $blib; }
use lib qw(blib/lib);
# t/foo.t use Test::More tests => 1;
diag("INC: @INC"); BEGIN { chdir "t" } require_ok('Foo');
$ pwd /home/me/Foo
$ perl -Mblib t/foo.t 1..1 # INC: /home/me/Foo/blib/arch /home/me/Foo/blib/lib ... ok 1 - require Foo;
$ perl -Mlib=blib/lib t/foo.t 1..1 # INC: blib/lib ... not ok 1 - require Foo; # Failed test 'require Foo;' # at t/foo.t line 8. # Tried to require 'Foo'. # Error: Can't locate Foo.pm in @INC (@INC contains: blib/lib ...) at (eval 3) line 2. # Looks like you failed 1 test of 1.
blib does more
ferreira on 2007-08-05T16:23:30
Yep, I know that blib tries hard to be handy. It also adds the architecture-dependent directories and does the right thing if used with arguments which end with '/' or 'blib'. I only stuffed this into the comment "it is much more complicated" to concentrate on the "WTF Cwd is doing there".