Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Auto install of a perl package if 'use' statement fails

by tilly (Archbishop)
on Nov 07, 2006 at 06:18 UTC ( #582572=note: print w/replies, xml ) Need Help??


in reply to Auto install of a perl package if 'use' statement fails

Yes. I've seen it done. I believe that Abigail did it, but I can't find the code.

Anyways the idea is simple. If you read the documentation for require, you'll find that you can put subroutines in @INC. Then you can pull tricks like this untested code:

use LWP::Simple qw(get); BEGIN { push @INC, sub { shift; my $file = shift; # eg "Foo/Bar.pm" my $content = get("http://myrepository.com/modules/$file"); if ($content) { open(my $fh, "<", \$content); return $fh; } else { return; } } }
(This one grabs the module off of a webserver, and loads it directly. No local installation needed! With older versions of Perl you'll need IO::Scalar instead of the open trick that I used to put the contents of a scalar into a filehandle.)

Replies are listed 'Best First'.
Re^2: Auto install of a perl package if 'use' statement fails
by Zubinix (Acolyte) on Nov 07, 2006 at 06:22 UTC
    Thanks for this. I will follow up on it :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://582572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2022-01-29 08:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (74 votes). Check out past polls.

    Notices?