Re: Auto install of a perl package if 'use' statement fails
by randyk (Parson) on Nov 07, 2006 at 06:09 UTC
|
| [reply] |
|
Thanks. This seems to be more along the lines of what I'm after.
| [reply] |
Re: Auto install of a perl package if 'use' statement fails
by tilly (Archbishop) on Nov 07, 2006 at 06:18 UTC
|
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.) | [reply] [d/l] |
|
Thanks for this. I will follow up on it :-)
| [reply] |
Re: Auto install of a perl package if 'use' statement fails
by Old_Gray_Bear (Bishop) on Nov 07, 2006 at 06:27 UTC
|
I also am afraid of 'automatic installation' tools. Like jbruger I prefer to exercise (a modicum) of control over what gets installed on my machines. It's not that I don't trust my User community, I can't. I am the 'responsible party' when the SEC auditors come through, and I don't want to have to explain what package Xyz::IOwn::TheWorld is doing on a (supposedly) secure server that happens to be handling credit-card data. I am willing to install what the user wants/needs (within reason), when asked, but I do need to have a piece of paper for the files.
And the other side of that coin is the tyographical error problem: The number of times I type "use warnigns;" is legion. With 'auto-install of package on use failure', then every time I typoed, Perl would have to take time out to search CPAN, determine that the module didn't exist, and report back; I'd get a lot grayer waiting. I'd be sorely tempted to build my own pragmas (with the appropriate mis-spelled name) to get around it. That would get to be both a maintenance headache and a distribution nightmare. I much prefer the current polite error message followed by a quick exit, stage left.
----
I Go Back to Sleep, Now.
OGB
| [reply] |
Re: Auto install of a perl package if 'use' statement fails
by syphilis (Archbishop) on Nov 07, 2006 at 05:53 UTC
|
| [reply] |
Re: Auto install of a perl package if 'use' statement fails
by jbrugger (Parson) on Nov 07, 2006 at 05:49 UTC
|
| [reply] |
|
This program is to operate in a build farm which has approx 200 Windows and Linux machines - so it multi-platform as well. I'd rather have a 'pull' mechanism over a 'push' mechanism so the correct perl modules get installed only on the required machines on demand.
| [reply] |
Re: Auto install of a perl package if 'use' statement fails
by Anonymous Monk on Nov 07, 2006 at 06:43 UTC
|
you could use an eval to test the existance of a particular module.
use CPAN;
eval "use My::Module"
or do {
CPAN::install("My::Module");
# or your code to install your custom module
};
| [reply] [d/l] |
Re: Auto install of a perl package if 'use' statement fails
by idsfa (Vicar) on Nov 07, 2006 at 14:22 UTC
|
See, for example, Remote Module "use" and the responses for a couple of solutions.
The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon
| [reply] |