Find::Lib(3pm)

πŸ“¦
version 1.04 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble

🌸 Find::Lib β€” the manual, but make it cute 🌸

Bestie. You found the page for Find::Lib, the Perl module whose whole entire job is: help you smartly find libs to use in the filesystem tree. That's the name, that's the game. No cap. πŸ’…


✨ VERSION ✨

Version 1.01 β€” she's grown, she's evolved, she's giving mature-but-still-fun.


πŸŽ€ SYNOPSIS πŸŽ€

#!/usr/bin/perl -w;
use strict;

## simple usage
use Find::Lib '../mylib';

## more libraries
use Find::Lib '../mylib', 'local-lib';

## More verbose and backward compatible with Find::Lib < 1.0
use Find::Lib libs => [ 'lib', '../lib', 'devlib' ];

## resolve some path with minimum typing
$dir  = Find::Lib->catdir("..", "data");
$path = Find::Lib->catfile("..", "data", "test.yaml");

$base = Find::Lib->base;
# or
$base = Find::Lib::Base;

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so the whole point of this module is to replace this:

use FindBin;
use lib "$FindBin::Bin/../bootstrap/lib";

…with something shorter. Because literally why type all that. This is especially iconic if your project has a lot of scripts (test scripts, I'm looking at you πŸ‘€). So instead you just go:

use Find::Lib '../bootstrap/lib';

The important differences between FindBin and Find::Lib are, and I need you to focus bestie:

  • symlinks and '..'

If you have symlinks in your path, she respects them. So basically you can forget you even have symlinks, because Find::Lib will do the natural thing (NOT ignore them) and resolve '..' correctly. Meanwhile FindBin just breaks if you do:

use lib "$Bin/../lib";

and you're currently chilling in a symlinked directory β€” because $Bin resolved to the filesystem path (without the symlink) and not the shell path. πŸ’€

  • convenience

It's faster to type, and more intuitive. (Exporting $Bin always felt weird to me, ngl.)


🌈 DISCUSSION 🌈

πŸ“ Installation and availability of this module

The usefulness of this module is seriously reduced if Find::Lib is not already in your @INC / $ENV{PERL5LIB} β€” classic chicken and egg problem πŸ₯šπŸ”. This is the big disadvantage of FindBin over Find::Lib: 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 management system, for instance).

🧚 modification of $0 and chdir (BEGIN blocks, other 'use')

As soon as Find::Lib is compiled, it saves the location of the script and the initial cwd (current working directory) β€” and those are the two pieces of information the module relies on to interpret the relative path given by the calling program.

If one of cwd, $ENV{PWD} or $0 is changed before Find::Lib has a chance to do its job, then Find::Lib will most probably die, saying "The script cannot be found". I don't know a workaround that. So be sure to load Find::Lib as soon as possible in your script to minimize problems (you are in control!).

(some programs alter $0 to customize the display 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 Find::Lib' and pass a list of paths to add to @INC. See the "BACKWARD COMPATIBILITY" section for more details on this topic.

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 disk.

🌟 base

Returns the detected base (the directory where the script lives in). It's a string, and is the same as $Find::Lib::Base.

🌟 catfile

A shortcut to File::Spec::catfile using Find::Lib's base.

🌟 catdir

A shortcut to File::Spec::catdir using Find::Lib's base.


πŸ’… BACKWARD COMPATIBILITY πŸ’…

In versions <1.0 of Find::Lib, the import arguments allowed you to specify a Bootstrap package. This option is now removed, breaking backward compatibility. I'm sorry about that, but that was a dumb idea of mine to save more typing. But it saves, like, 3 characters at the expense of readability. So, I'm sure I didn't break anybody, because probably no one was relying on a stupid behaviour. πŸ™ˆ

However, the multiple libs argument passing is kept intact: you can still use:

use Find::Lib libs => [ 'a', 'b', 'c' ];

where "libs" is a reference to a list of path to add to @INC.

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, rlib, local::lib <http://blog.cyberion.net/2009/10/ive-done-something-bad-i-broke-backward-compatibility.html>


πŸ‘‘ 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=Find-Lib>. 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.

Jonathan Steinert (hachi) for doing all the conception of 0.03 shell expansion mode with me.


⭐ 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 Find::Lib

You can also look for information at:

  • AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/Find-Lib>

  • CPAN Ratings

<http://cpanratings.perl.org/d/Find-Lib>

  • RT: CPAN's request tracker

<http://rt.cpan.org/NoAuth/Bugs.html?Find-Lib>

  • Search CPAN

<http://search.cpan.org/dist/Find-Lib>


Copyright 2007, 2009 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.


and that's the whole page bestie, no notes, go add some libs to @INC responsibly πŸ’–

Signing off from the perl v5.32.0 era, dated 2021-01-07 β€” she's vintage, she's iconic, she still works, periodt. πŸŽ€βœ¨

πŸ“¦ where this page comes from