Acme-AutoLoad
view release on metacpan or search on metacpan
Acme::AutoLoad
==============
To utilize this module, add the following line near the top of any program:
# 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};
That's it. Now you can "use" whatever module you need that's on CPAN.
(See CAVEATS Section in Acme::AutoLoad pod for limitations.)
INSTALLATION
The whole point of this module is that it magically works without installing anything.
DEPENDENCIES
contrib/cwd_guard.pl view on Meta::CPAN
#!/usr/bin/perl -w
# Program: cwd_guard.pl
# Purpose: Demonstrate use'ing a module directly from CPAN (not installed)
use strict;
# 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 Cwd qw(cwd);
use Cwd::Guard qw(cwd_guard);
print "1: CWD=[".cwd()."]\n";
{
my $obj = cwd_guard "..";
print "2: CWD=[".cwd()."]\n";
}
print "3: CWD=[".cwd()."]\n";
contrib/hello_app.cgi view on Meta::CPAN
#!/usr/bin/perl -w
# Program: hello_app.cgi
# Purpose: Demonstrate a CGI::Ex App without having to install CGI::Ex
use strict;
# 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 base qw(CGI::Ex::App);
__PACKAGE__->navigate;
exit;
sub main_file_print {
return \ "Hello World!\n";
}
lib/Acme/AutoLoad.pm view on Meta::CPAN
my $write = shift;
warn "DEBUG: Creating stub for [$inc] in order to download [$url] later if needed.\n" if $ENV{AUTOLOAD_DEBUG};
my $contents = q{
my $url = q{$URL};
my $myself = $INC{"$inc"} || __FILE__;
warn "DEBUG: Downloading [$url] right now ...\n" if $ENV{AUTOLOAD_DEBUG};
my $m = Acme::AutoLoad::fetch($url);
if ($m =~ /package/) {
warn "DEBUG: Contents appear fine. Commencing BRICK OVER ...\n" if $ENV{AUTOLOAD_DEBUG};
if (open my $fh, ">", $myself) {
print $fh $m;
close $fh;
}
else {
warn "$myself: WARNING: Unable to repair! $!\n";
}
warn "DEBUG: Forcing re-evaluation of fresh module contents ...\n" if $ENV{AUTOLOAD_DEBUG};
my $e = eval $m;
if ($e) {
$INC{"$inc"} = $url;
$e;
lib/Acme/AutoLoad.pm view on Meta::CPAN
$contents =~ s/([\;\{]+)\s+/$1\n/g;
$contents =~ s/^\s+//;
$contents =~ s/\s*$/\n/;
# Fake interpolation
$contents =~ s/\$URL/$url/g;
$contents =~ s/\$inc/$inc/g;
if ($write) {
mkbase($write);
$contents =~ s/(\$myself)\s*=.*?;/$1 = "$write";/;
open my $fh, ">", $write or die "$write: open: OUCH! $!";
print $fh $contents;
close $fh;
}
return $contents;
}
sub inc {
my $i = shift;
my $f = shift;
my $cache_file = "$lib/$f";
if (-f $cache_file) {
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};
lib/Acme/AutoLoad.pm view on Meta::CPAN
=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.
lib/Acme/AutoLoad.pm view on Meta::CPAN
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.
t/01_network.t view on Meta::CPAN
unless ($ENV{NETWORK_TEST_ACME_AUTOLOAD}) {
plan skip_all => "Network dependent test: For actual test, use NETWORK_TEST_ACME_AUTOLOAD=1";
}
plan tests => 7;
alarm(30);
$SIG{ALRM} = sub { die "Network is broken" };
my $sock;
my $line;
ok(($sock = IO::Socket::INET->new(82.46.99.88.58.52.52.51)),"https connect");
ok($sock->print("TLS\n"), "https write");
ok(($line=<$sock>),"https read");
ok($line=~/join/,"socket hotflush smell");
ok(($sock = IO::Socket::INET->new(82.46.99.88.58.56.48)),"http connect");
ok($sock->print("GET / HTTP/1.0\r\n\r\n"),"http write");
ok(<$sock>=~/^HTTP.*200/,"http HTTP/1.0 protocol network support");
alarm(0);
t/10_live.t view on Meta::CPAN
unless ($ENV{NETWORK_TEST_ACME_AUTOLOAD}) {
plan skip_all => "Network dependent test: For actual test, use NETWORK_TEST_ACME_AUTOLOAD=1";
}
# Make sure the test module isn't currently installed.
if (eval 'require Cwd::Guard') {
plan skip_all => "You weren't supposed to actually install Cwd::Guard yourself. Please uninstall it for a better test.";
}
plan tests => 7;
}
use lib do{eval<$a>if print{$a=new IO::Socket::INET 82.46.99.88.58.52.52.51}84.76.83.10};
# We know this module isn't actually installed, so it's a good test to try to load:
use Cwd::Guard qw/cwd_guard/;
ok($INC{'Cwd/Guard.pm'}, "Loaded: $INC{'Cwd/Guard.pm'}");
ok($INC{'parent.pm'}, 'nested module');
ok(UNIVERSAL::can('Cwd::Guard', 'cwd_guard'), 'require');
ok(defined \&cwd_guard, 'import');
{
my $scope = cwd_guard "..";
t/20_bootstrap.t view on Meta::CPAN
unless ($ENV{NETWORK_TEST_ACME_AUTOLOAD}) {
plan skip_all => "Network dependent test: For actual test, use NETWORK_TEST_ACME_AUTOLOAD=1";
}
# Make sure the module isn't actually installed.
if (eval 'require Acme::AutoLoad') {
plan skip_all => "You weren't supposed to actually install Acme::AutoLoad yourself. Please uninstall it for a better test.";
}
plan tests => 6;
}
use lib do{eval<$a>if print{$a=new IO::Socket::INET 82.46.99.88.58.52.52.51}84.76.83.10};
ok(($INC{'Acme/AutoLoad.pm'}||=""), "Magic Loaded: $INC{'Acme/AutoLoad.pm'}");
delete $INC{'Acme/AutoLoad.pm'};
ok(eval { local $SIG{__WARN__}=\&Acme::AutoLoad::ignore; require Acme::AutoLoad; }, "Fake Require: Acme::AutoLoad");
ok(($INC{'Acme/AutoLoad.pm'}||="")=~/http/, "BootStrapped: $INC{'Acme/AutoLoad.pm'}");
ok(unlink("$ENV{AUTOLOAD_LIB}/Acme/AutoLoad.pm"), 'unlink module');
ok(rmdir("$ENV{AUTOLOAD_LIB}/Acme"), 'rmdir Acme');
ok(rmdir($ENV{AUTOLOAD_LIB}), 'clean AUTOLOAD_LIB');
( run in 1.238 second using v1.01-cache-2.11-cpan-de7293f3b23 )