Acme-AutoLoad
view release on metacpan or search on metacpan
lib/Acme/AutoLoad.pm view on Meta::CPAN
sub get {
local $_ = shift;
s{^http(s|)://}{}i;
s{^([\w\-\.\:]+)$}{$1/};
s{^([\w\-\.]+)/}{$1:80/};
if (m{^([\w\-\.]+:\d+)(/.*)}) {
my $host = $1;
my $path = $2;
my $r = new IO::Socket::INET $host or return warn "$host$!\n";
$host =~ s/:\d+$//;
print $r "GET $path HTTP/1.0\r\nUser-Agent: Acme::AutoLoad/url::get\r\nHost: $host\r\n\r\n";
local $/;
return [split/[\r\n]{3,}/,<$r>,2]->[1];
}
return "";
}
$INC{"Acme/AutoLoad.pm"} ||= __FILE__;
warn "DEBUG: Congratulations! Acme::AutoLoad was compiled fine.\n" if $ENV{AUTOLOAD_DEBUG};
1;
__END__
=pod
=head1 NAME
Acme::AutoLoad - Automatically load uninstalled CPAN modules on the fly.
=head1 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;
=head1 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.
=head1 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.
=head1 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!
=head1 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.
=head1 CAVEATS
=head2 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.
=head2 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.
=head2 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.)
=head2 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.
=head1 ENVIRONMENT VARIABLES
There are a few ENV settings you can configure to customize the behavior of Acme::AutoLoad.
=head2 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.
=head2 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.
( run in 0.750 second using v1.01-cache-2.11-cpan-39bf76dae61 )