Michael Peters wrote on 7/7/10 8:43 AM:

> 
> It's verbose, but the only thing I know of is:
> 
> BEGIN {
>    eval { require Data::Dumper; Data::Dumper::import() };
>    die "Can't find Data::Dumper module: $@" if $@;
> }
> 
> repeated for each one.

or

 my @modules = qw( Data::Dumper );
 for my $mod (@modules) {
     eval "use $mod";
     die "Can't find $mod module: $@" if $@;
 }

You can use 'use Foo' in a string eval and still get the defer-till-runtime help
of $@ and 'require':

# 'use' evaluated at compile-time
% perl -e 'print Data::Dump::dump(\{}),$/; use Data::Dump'
\{}

# 'require' evaluated at
% perl -e 'print Data::Dump::dump(\{}); require Data::Dump'
Undefined subroutine &Data::Dump::dump called at -e line 1.

# like 'require', deferred till run-time
% perl -e 'print Data::Dump::dump(\{}),$/; eval "use Data::Dump";'
Undefined subroutine &Data::Dump::dump called at -e line 1.

But Michael is correct about the security issues and the logs. Love your logs;
they will love you back.

-- 
Peter Karman  .  http://peknet.com/  .  [email protected]

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################

Reply via email to