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.
package SomeDatabaseStuff; sub my_funny_sql{ my ($dbh) = @_; $dbh->do('my great query'); }
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
my_funny_sql($dbh);
But it can also be called like this:
$dbh->SomeDatabaseStuff::my_funny_sql();
This is especially nice if you have additional parameters that you want to visually seperate from $dbh:
$dbh->SomeDatabaseStuff::my_funny_sql ( 'some parameter', 12 , 34 );
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):
package MoreDatabaseStuff; @MoreDatabaseStuff::ISA = qw( SomeDatabaseStuff); # no subroutines here $dbh->MoreDatabaseStuff::my_funny_sql(); # ends up being dispatched properly # to the sub in the parent SomeDatabaseStuff
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).
my $dbh = DBI->connect('....'); $dbh->SomeDatabaseStuff::my_funny_sql;
In reply to $object->UnrelatedPackage::some_subroutine() by Thilosophy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |