[tpm] eval oddness

Madison Kelly linux at alteeve.com
Wed Dec 9 18:49:25 PST 2009


Hi all,

   This may be due to my ignorance, but I am having a problem that I 
don't *think* I should be.

   I've got a set of methods in my module that loads various other 
modules wrapped in 'eval's so that I can handle missing modules a little 
more gracefully. All of these work except one.

   For example; This works:

-----------------------------------------
# Script
use AN::Tools;
my $an=AN::Tools->new();
$an->_load_net_dbus();

# Module
sub _load_net_dbus
{
	my $self=shift;
	
	eval 'use Net::DBus;';
	if ($@)
	{
		print "Gak! $@\n";
		return (undef);
	}
	else
	{
		# Good, record it as loaded.
		$self->_net_dbus_loaded(1);
		print "Net::DBus loaded.\n";
	}
	
	return (0);
}
-----------------------------------------

   Now though, I've got one that doesn't... The main difference that I 
can see is the 'use base ...'.

-----------------------------------------
# Script
$an->_load_net_dbus_object();

# Module
sub _load_net_dbus_object
{
	my $self=shift;
	
	eval 'use base qw(Net::DBus::Object);';
	if ($@)
	{
		print "Gak! $@\n";
		return (undef);
	}
	else
	{
		# Good, record it as loaded.
		$self->_net_dbus_object_loaded(1);
		print "Net::DBus::Object loaded.\n";
	}
	
	return (0);
}
-----------------------------------------

   It *looks* like it loads in that '$@' isn't set. However, when I try 
to use any of the methods in Net::DBus::Object, it errors.

   Is there something about 'base' that could be messing this up or is 
it something else? For testing, if I check that the 
'$an->_load_net_dbus_object();' call returns '0' and then call:

eval 'use base qw(Net::DBus::Object);';

   From the main script, it does work, so it doesn't seem to be the eval 
itself that's the problem.

Thanks all!

Madi


More information about the toronto-pm mailing list