Acme-RemoteINC
view release on metacpan or search on metacpan
lib/Acme/RemoteINC.pm view on Meta::CPAN
package Acme::RemoteINC;
use 5.008;
use strict;
use warnings;
use Net::FTP;
use File::Temp;
our $VERSION = 0.15;
sub new {
my($class, %args) = @_;
my $self = {};
bless $self, $class;
foreach my $k ( qw(ftp host user password perl_root) )
{ $self->{$k} = $args{$k} if $args{$k} }
unless( $self->{ftp} ) {
my $ftp = new Net::FTP($self->{host}) or return;
$ftp->login( $self->{user} => $self->{password} ) or return;
$self->{ftp} = $ftp;
}
# register ourself in @INC.
push @INC, $self;
return $self;
}
sub Acme::RemoteINC::INC {
my($self, $filename) = @_;
my($tmpFH, $tmpname) = File::Temp::tmpnam();
my @subdirs;
if(ref $self->{perl_root}) { @subdirs = @{$self->{perl_root}} }
else { push @subdirs, $self->{perl_root} }
foreach my $path (@subdirs) {
$self->{ftp}->cwd($path);
return $tmpFH if $self->{ftp}->get($filename, $tmpname);
}
return undef;
}
=head1 NAME
Acme::RemoteINC - Slowest Possible Module Loading
=head1 DESCRIPTION
For your SlowCGI pleasure, loads perl modules via FTP from remote sites.
Please don thick rubber gloves and consider version and binary XS module
compatibility before using. Requires Perl 5.8 or greater.
=head1 (IR)RATIONALE
Who do you want to kid today? A paranoid ISP admin who won't let you load
your favorite CPAN module on his system? Yourself, for considering this as
a valid solution to a social problem like that one?
=head1 SYNOPSIS
use strict;
use warnings;
BEGIN {
require Acme::RemoteINC;
my $rinc = new Acme::RemoteINC(
host => 'ftp.esoteric-perl.com',
user => 'anonymous',
password => 'pwd@myhost.com',
perl_root => '/usr/lib/perl5/site_perl/5.8.1'
);
}
use DBI; # load local DBI by default
use DBD::Esoterica; # if cannot load locally, will try the FTP method
...etc.
( run in 1.998 second using v1.01-cache-2.11-cpan-39bf76dae61 )