lib::xi - Installs missing modules on demand


This document describes lib::xi version 0.11.


    # to install missing libaries automatically
    $ perl -Mlib::xi

    # with cpanm options
    $ perl -Mlib::xi=-q

    # to install missing libaries to extlib/ (with cpanm -l extlib)
    $ perl -Mlib::xi=extlib

    # with cpanm options
    $ perl -Mlib::xi=extlib,-q

    # with cpanm options via env
    $ PERL_CPANM_OPT='-l extlib -q' perl -Mlib::xi


When you execute a script found in, for example, gist, you'll be annoyed at missing libraries and will install those libraries by hand with a CPAN client. We have repeated such a task, which violates the great virtue of Laziness. Stop doing it, making computers do it!

lib::xi is a pragma to install missing libraries automatically if and only if they are required.

The mechanism, using @INC hook, is that when the perl interpreter cannot find a library required, this pragma try to install it with cpanm(1) and tell it to the interpreter.


The import method

use lib::xi ?$install_dir, ?@cpanm_opts

Setups the lib::xi hook into @INC.

If $install_dir is specified, it is used as the install directory as cpanm --local-lib $install_dir, adding $install_dir/lib/perl5 to @INC Note that $install_dir will be expanded to the absolute path based on where the script is. That is, in the point of @INC, use lib::xi 'extlib' is almost the same as the following code:

    use FindBin;
    use lib "$FindBin::Bin/extlib/lib/perl5";

@cpanm_opts are passed directly to cpanm(1). Note that if the first argument starts with -, it is regarded as @cpanm_opts, so you can simply omit the $install_dir if it's not needed.


There are similar modules to lib::xi, namely CPAN::AutoINC and Module::AutoINC, which use to install modules; the difference is that lib::xi supports local::lib (via cpanm -l) and has little overhead.


Perl 5.8.1 or later.


All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.


cpanm (App::cpanminus)

"require" in perlfunc for the @INC hook specification details




Fuji, Goro (gfx) <>


Copyright (c) 2011, Fuji, Goro (gfx). All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.