[tpm] eval oddness

Dave Doyle dave.s.doyle at gmail.com
Wed Dec 9 19:27:07 PST 2009


I do not think that means what you think that means. :)

Can I ask why you're doing "use base qw(Net::DBus::Object);" as opposed to
"use Net::DBus::Object;" ?  The 'use base' is nonsensical in this context as
it's modifying the @ISA array.  It's essentially saying "This class is a
subclass of Net::DBus::Object" and not actually making any part of
Net::DBus::Object available to you.  I suspect just doing use
Net::DBus::Object and you'll be fine.

Though I'm hardpressed to explain why, using "require" instead of "use"
seems to be more canonical when dynamically loading modules.  I'm sure
someone far smarter than I on this list could explain that.  I suspect it's
the difference between bareword and string (bareword loads a module, string
loads the filename specifically instead of searching %INC for it).  There's
also import voodoo that won't happen (unless you do the voodoo yourself) but
if you're only loading OO modules this shouldn't be a big deal.

D
--
dave.s.doyle at gmail.com


On Wed, Dec 9, 2009 at 9:49 PM, Madison Kelly <linux at alteeve.com> wrote:

> 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
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20091209/c8ce003c/attachment.html>


More information about the toronto-pm mailing list