ful - a useful "find upper lib" pragma that ascends dirs to include module directories in @INC
.
One line to rule them all.
use ful;
Brings the first lib/
directory found by directory ascencion and adds it to @INC
.
Instead of:
use lib::relative '../../lib';
# or
use FindBin;
use lib "$FindBin::Bin/../lib";
# or even
BEGIN {
use Path::Tiny;
my $base = path(__FILE__)->parent;
$base = $base->parent until -d "$base/lib" or $base->is_rootdir;
unshift @INC, "$base/lib";
}
When you're working within a-script.pl
when your project looks like this:
project-root/
├── bin/
│ └── utils/
│ └── a-script.pl
├── lib/
│ └── Some/
│ └── Module.pm
├── vendor/
│ └── SomeOrg/
│ └── Some/
│ └── Module.pm
Just drop the line before your other use
statements:
use ful;
use Some::Module;
And that's all.
If you need more than just the project-root/lib
dir, you can do this:
use ful qw/vendor lib/;
use Some::Module;
use SomeOrg::Some::Module;
crum()
Returns the parent directory for the latest addition to
@INC
.
use ful \%options;
libdirs => \@dirs
Equivalent to
use ful qw/lib vendor/;
but can be combined with all other options.# multiple @INC dirs use ful { libdirs => [qw/lib vendor/] }; # combined with another option use ful { libdirs => [qw(lib vendor/lib)], dir => 'vendor/lib', };
file => $file
,target_file => $file
,target => $file
Finds an existing file to add a sibling directory to
@INC
.# adds 'lib' use ful { file => '.file-in-project-root' };
dir => $dname
,has_dir => $dname
,child_dir => $dname
Finds an existing directory to add a sibling directory to
@INC
.# adds 'lib' use ful { dir => 'bin' };
git => 1
Finds a git repository to add a sibling directory to
@INC
.# adds 'lib' use ful { git => 1 };
MIT License
Copyright (c) 2020 Ryan Willis <code@ryanwillis.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0.11
Support is by the author. Please file bug reports or ask questions at https://github.com/ryan-willis/ful.pm/issues.