NAME
Acme::AutoLoad - Automatically load uninstalled CPAN modules on the fly.
SYNOPSYS
# Acme::AutoLoad MAGIC LINE:
use lib do{use IO::Socket;eval<$a>if print{$a=new IO::Socket::INET 82.46.99.88.58.52.52.51}84.76.83.10};
use some::cpan::module;
my $obj = some::cpan::module->new;
DESCRIPTION
Are you tired of everyone whining that your perl script doesn't work for other people because they didn't install some CPAN module that you "use" in your code, but you don't want to keep explaining to them how to install that silly dependency? Well then, this is just what you need.
INSTALL
Unlike most other modules on CPAN, this one is never intended to be installed. It works by simply adding only one line, i.e., the "MAGIC LINE" from the SYNOPSYS above. You can just copy/paste and then "use" whatever CPAN module you want after that. It even automatically loads the latest version of Acme::AutoLoad at run-time directly from CPAN. The optional "MAGIC LINE" comment is only to direct people reading your code back here to this documentation.
The line is intentionally short in order to minimize effort to use it. It also can be easily used from commandline since it contains no quotes.
DISCLAIMER
This module is not recommended for use in production environments. This MAGIC LINE will eval code from the network, which is generally a BAD IDEA! Relying on remote network is generally dangerous for security and functionality. For example, if CPAN or any required network endpoint ever goes down or malfunctions or gets hacked, then it could cause problems for you. See also CAVEATS Section "2. Slow" below. USE AT YOUR OWN RISK!
PREREQUISITES
There are intentionally very few modules required to be installed in order to use this module. That is the entire purpose for this module. In fact, this module itself works without even being installed! The only module required is IO::Socket, which comes stock with all perl distributions now.
CAVEATS
1. Network
Network access is required in order to download the modules from CPAN, including Acme::AutoLoad itself. It uses port 80 and port 443 to connect out.
2. Slow
Also, because of all the network traffic used, this module can be quite slow, especially the first time it is used since none of the cache files exist yet. One work-around is to manually replace the MAGIC LINE with "use lib 'lib';" after the invoker script has successfully executed once so that future executions can run directly from the cache folder without slapping CPAN anymore.
3. Write
Write access is required for storing a local cache of the CPAN module in order to save time for future invocations. (See AUTOLOAD_LIB below for more details.)
4. Pure Perl
This only works for Pure Perl CPAN modules at this time. If you use modules with XS or bytecode, you will probably have to truly install it first.
5. Load Precedence
You must always load the main distribution module first, even if you don't actually need to use that module anywhere.
# For example, if all you need is Net::DNS::Resolver
# You still have to load Net::DNS first.
use Net::DNS;
use Net::DNS::Resolver;
6. Irregular Distros
And for the same reason, those crazy distribution names that aren't really a module are more difficult to load on the fly. One workaround is with eval.
# For example, Mail::Cap is part of the MailTools distribution.
# But MailTools.pm doesn't exist, so you have to eval it.
BEGIN { eval { require MailTools; } }
use Mail::Cap;
ENVIRONMENT VARIABLES
There are a few ENV settings you can configure to customize the behavior of Acme::AutoLoad.
AUTOLOAD_LIB
You can choose where the CPAN cache files will be written to by using the AUTOLOAD_LIB setting. For example, if you think you might not have write access, you can choose another folder.
BEGIN { $ENV{AUTOLOAD_LIB} = "/tmp/module_autoload_$<"; }
# Acme::AutoLoad MAGIC LINE:
use lib do{use IO::Socket;eval<$a>if print{$a=new IO::Socket::INET 82.46.99.88.58.52.52.51}84.76.83.10};
The default is "lib" in the current directory.
AUTOLOAD_DEBUG
You can enable verbose debugging to see more how it works or if you are having trouble with some modules by setting AUTOLOAD_DEBUG to a true value. The default is off.
AUTOLOAD_SRC
You can use AUTOLOAD_SRC to specify the mapper engine to ask where the latest location of the module is.
# For example
BEGIN { $ENV{AUTOLOAD_SRC} = "http://metacpan.org/release"; }
The default is "http://fastapi.metacpan.org/v1/release" .
NETWORK_TEST_ACME_AUTOLOAD
In order to really test the test suite, the NETWORK_TEST_ACME_AUTOLOAD environment variable must be set to a true value, otherwise none of the network dependent tests will be run. For example:
NETWORK_TEST_ACME_AUTOLOAD=1 make test
SEE ALSO
lib::xi - Similar on-demand functionality except nothing required to install.
local::lib - Similar local folder installation functionality except nothing to install.
App::cpanminus - Similar remote network "cpanmin.us" execution functionality except smaller.
CPAN - Actually installs CPAN modules instead of using a local cache.
cpan2rpm - Similar code to lookup latest module without having to configure any CPAN.pm bloat.
AUTHOR
Rob Brown (bbb@cpan.org) - Acme::AutoLoad code and RCX maintainer.
COPYRIGHT AND LICENSE
Copyright (C) 2011-2020 by Rob Brown
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.