Acme-AutoLoad
view release on metacpan or search on metacpan
- Ported to use the new fastapi.metacpan.org
0.04 Sun Feb 8 10:00 2015
- More accurate t/01_network.t test for HTTP/0.9 support.
- Shortened MAGIC a few more characters.
0.03 Sat Feb 7 23:00 2015
- More gracefully handle case where MANIFEST contains
prefix, but not the full stub, such as:
"MLEHMANN/common-sense-3.73/sense.pm"
- Adjust %INC assignment for sub modules found in lib.
0.02 Tue Sep 13 14:00 2011
- Documental cleanup.
- No functional changes.
0.01 Mon Sep 5 14:00 2011
- Initial release
- Created by h2xs -X Module::AutoLoad
contrib/hello_app.cgi view on Meta::CPAN
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 CGI::Ex;
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
use strict;
use warnings;
use base qw(Exporter);
our $VERSION = '0.08';
our $last_fetched = "";
our $lib = "lib";
our $hook = \&inc;
sub ignore {}
sub import {
warn "DEBUG: Congratulations! Acme::AutoLoad has been loaded.\n" if $ENV{AUTOLOAD_DEBUG};
$lib = $ENV{AUTOLOAD_LIB} if $ENV{AUTOLOAD_LIB};
if ($lib =~ m{^[^/]}) {
eval {
require Cwd;
$lib = Cwd::abs_path($lib);
};
}
push @INC, $lib, $hook if $hook;
$hook = undef;
return \&ignore;
}
sub mkbase {
my $path = shift;
if ($path =~ s{/+[^/]*$ }{}x) {
return 1 if -d $path;
}
die "$path: Not a directory\n" if lstat $path;
if (mkbase($path)) {
warn "DEBUG: mkbase: Creating [$path] ...\n" if $ENV{AUTOLOAD_DEBUG};
return mkdir $path, 0755;
}
return 0;
}
sub fetch {
my $url = shift;
my $recurse = shift || {};
$url = full($url) unless $url =~ m{^\w+://};
my $contents = get($url);
$last_fetched = $url;
if ($contents =~ m{The document has moved <a href="([^<>]+)">}) {
my $bounce = $1;
if ($recurse->{$bounce} && $recurse->{$bounce} > 2) {
return $contents;
}
$recurse->{$bounce}++;
return fetch($bounce, $recurse) if $recurse->{total}++<20;
}
return $contents;
}
# full
# Turn a relative URL into a full URL
sub full {
my $rel = shift;
if ($rel =~ m{http://} || $last_fetched !~ m{^(http://[^/]+)(/?.*)}) {
return $rel;
}
my $h = $1;
my $p = $2;
if ($rel =~ m{^/}) {
return "$h$rel";
}
$p =~ s{[^/]*$ }{}x;
return "$h$p$rel";
}
# fly
# Create a stub module to load the real file on-the-fly if needed.
sub fly {
my $inc = shift;
my $url = shift;
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/) {
lib/Acme/AutoLoad.pm view on Meta::CPAN
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) {
warn "$cache_file: Broken module. Can't continue.\n";
return ();
}
mkbase($cache_file) or die "$cache_file: Unable to create! $!\n";
shift @INC if $INC[0] eq \&ignore;
lib/Acme/AutoLoad.pm view on Meta::CPAN
}
if (open my $fh, "<", $cache_file) {
$INC{$f} = $cache_file;
return $fh;
}
return ();
}
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";
t/01_network.t view on Meta::CPAN
use strict;
use Test::More;
use IO::Socket;
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);
( run in 0.292 second using v1.01-cache-2.11-cpan-4d50c553e7e )