Exposing my ignorance, wanting help with use!

Nigel Rantor wiggly at wiggly.org
Wed Feb 14 15:04:01 GMT 2007


Off the top of my head you should be using the interpolated eval to do 
the require:

eval "require $class;";

instead of

eval { require $class; };

see perlmod in the docs...

Peter Hickman wrote:
> Unfortunately my fount of all things Perl is away today and as I look 
> around the office I see that I am surrounded by Java programmers. So no 
> help there, I'll just have to expose my ignorance to the whole world.
> 
> I have this little project I am working on that involves the following 
> code:
> 
>    my %handlers = $t->get_handlers();
> 
>    foreach my $handler ( keys %handlers ) {
>        my $class  = $handlers{$handler}{class};
>        my $config = $handlers{$handler}{config};
>        eval {
>            require $class;
>            $self->{dispatcher}->add_dispatcher( $handler, 
> $class->new($config) );
>        };
> 
>        die "Error loading dispatcher '$class': $@\n" if $@;
>    }
> 
> The problem is the require in the eval. When it is called with class set 
> to, say, Stupid::Dispatcher::XSQL I get the following error:
> 
> Error loading dispatcher 'Stupid::Dispatcher::XSQL': Can't locate 
> Stupid::Dispatcher::XSQL in @INC (@INC contains: /sw/lib/perl5 
> /sw/lib/perl5/darwin 
> /System/Library/Perl/5.8.6/darwin-thread-multi-2level 
> /System/Library/Perl/5.8.6 
> /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 
> /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level 
> /Network/Library/Perl/5.8.6 /Network/Library/Perl 
> /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level 
> /System/Library/Perl/Extras/5.8.6 
> /Library/Perl/5.8.1/darwin-thread-multi-2level /Library/Perl/5.8.1 .) at 
> /Library/Perl/5.8.6/Stupid/Control.pm line 35.
> 
> Here's the rub, the file is located at:
> 
> [stupid]$ ll /Library/Perl/5.8.6/Stupid/Dispatcher/XSQL.pm
> -r--r--r--   1 root  admin  1520 Feb 14 13:50 
> /Library/Perl/5.8.6/Stupid/Dispatcher/XSQL.pm
> [stupid]$
> 
> Which you can see is in @INC. I can -M the file and even perl -e 
> 'require Stupid::Dispatcher::XSQL; print 1;' the damn thing but the 
> above code will not work. Even sticking a use Stupid::Dispatcher::XSQL 
> in the code does not help.
> 
> Help. I do not understand what is going on.
> 



More information about the london.pm mailing list