[Thamesvalley-pm] checking for perl modules
Will Hawes
wdhawes at gmail.com
Fri Jun 13 04:57:15 PDT 2008
2008/6/13 Greg Matthews <gmatt at nerc.ac.uk>:
> Is there an easy way to run a check for perl modules at the start of a
> script so that it can present a friendly/useful message to the user
> along the lines of:
>
> "This script requires the following modules which don't appear to be
> installed on your system:"
>
> rather than crashing out with something like:
>
> Can't locate IO/Socket/SSL.pm in @INC (@INC contains: /etc/perl
> /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5
> /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8
> /usr/local/lib/site_perl .) at /usr/share/perl5/Net/LDAP.pm line 970,
> <STDIN> line 1.
>
> which is pretty horrendous to the casual user.
Not something I've ever done, but you could probably do something like
(untested, btw):
#!/usr/bin/perl
BEGIN {
my @required_modules = ( qw/ Module1 Module2 / );
foreach( @required_modules ) {
eval { require "$_"; };
if( $@ ) {
die "You don't appear to have module '$_' installed on your system.";
}
}
}
... rest of script here ...
HTH, Will
More information about the Thamesvalley-pm
mailing list