in reply to Re^2: $object->UnrelatedPackage::some_subroutine()
in thread $object->UnrelatedPackage::some_subroutine()

Thanks for that knowledge bit.

In my particular case this trick will not mess a program, because I use it inside AUTOLOAD so coderefs should not pass through.

But...let's see, you can call

$Tcl::Tk::Widget::AUTOLOAD=sub{print 'tricky hacky sub'}; Tcl::Tk::Widget::AUTOLOAD($object)
Accidentally, it still not pass through as in that AUTOLOAD I see:
my $method = $Tcl::Tk::Widget::AUTOLOAD; # Separate method to autoload from (sub)package $method =~ s/^(Tcl::Tk::Widget::((MainWindow|$ptk_w_names)::)?)// or die "weird inheritance ($method)";
But I get your point: I should closer revise that module for similar things.

Also, in my case, in Tcl::Tk module AUTOLOAD is used to redirect a method to Tcl/Tk system, so it is not OO trick but rather some kind of redirecting methods to Tcl/Tk.

PS. I was talking about Tcl::Tk as I do not have anything other resembling OO

Replies are listed 'Best First'.
Re^4: $object->UnrelatedPackage::some_subroutine()
by tilly (Archbishop) on Feb 21, 2005 at 19:47 UTC
    When I suggested typeglobbing closures I didn't mean to create AUTOLOAD that way rather than using the usual subroutine definition, I meant that you should create lots of very similar subroutines from a central template rather than try to dynamically dispatch them from AUTOLOAD.

    There are a number of wins from doing so, two of the bigger ones being that it plays better with inheritance, and you don't have to put all of the dynamic logic in one big routine.