Rob Dixon ha scritto:
[...]
It works but I prefer to write all into 1 script.
I wasn't clear what your purpose was, as running a program will report any
module that is missing anyway. I can only guess that you want them all checkd in
one pass, and I have written this code that will do that for you. Just paste
this code right before any 'use MODULE' statements at the start of the program,
and if any fail to load it will die with a list of missing modules.
Thanks a lot for your detailed reply: I'll study it carefully.
I know that if you haven't the required module installed, you'll be
notified on the shell.
But I'm trying to write an Amarok script and I want the user to be
notified if he lacks any module.
Launching the script inside Amarok, the error due to missing modules is
not clear.
However, to set some code before the use MODULE directives is something
I could never imagine, due to my still poor perl knowledge.
I thought that if some modules were missing, I had errors also if some
instructions were put before the use MODULE directives.
Bye
All it does is to put some stub code in place of any missing modules, with an
import routine that just pushes the name of the package onto array
@main::NOTFOUND. Then the CHECK block code just reports the contents of that
array and dies if it's not empty.
There are a number of issues with it, such as it only detecting missing modules
that have had their import routine called, but that's what use does anyway.
There are also probably others, but it's a start. See how you get on with it.
HTH,
Rob
use strict;
use warnings;
our @NOTFOUND;
BEGIN {
push @INC, sub {
my ($self, $package) = @_;
$package =~ s#/#::#g;
$package =~ s#\.pm$##;
my $module = qq{
package $package;
sub import { push [EMAIL PROTECTED]::NOTFOUND, '$package'; }
1;
};
open my $fh, '<', \$module;
return $fh;
}
}
CHECK {
if (@NOTFOUND) {
die "Modules not installed: ". join ', ', @NOTFOUND;
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/