|Do you know where your variables are?|
$object->UnrelatedPackage::some_subroutine()by Thilosophy (Curate)
|on Feb 18, 2005 at 03:09 UTC||Need Help??|
I just discovered (thanks to diotalevi for pointing me at it) an arcane (?) but possibly useful feature of Perl's object method calling syntax: You can specify a fully qualified (including the package) name for the method.
You (or at least I) have until now called the subroutine (note that it is not even intended to be a method at all) like so
But it can also be called like this:
This is especially nice if you have additional parameters that you want to visually seperate from $dbh:
Note that this syntax can only be used when $dbh is indeed a blessed reference (although its class seems to be not involved in the "method" lookup anymore), and if the name of subroutine you want is fully qualified (otherwise the normal method lookup will occur, starting at the package of $dbh)
This even works in combination with @ISA-inheritence (although the search starts at the package of the subroutine, not the package of the object as usual):
All this is probably mentioned in the Perl OO docs, but it was new to me.
Update: I forgot to point out the important detail that $dbh is a DBI connection handle (and not something blessed into SomeDatabaseStuff).