August 1999 | Perl Hardware Store | Slide #19 |
Adding a new Method to a Package
You wish that $dbh supported a myquery method
Subclassing is a pain in the butt
Do this instead:
sub Msql::myquery { my $dbh = shift; # Just stick the method here, dummy. }
Now you can say
@list_of_hashes = $dbh->myquery(...);
myquery is inherited by Msql's subclasses just the way you'd
want.Downside: The programmer in the next cubicle might do the same thing
If you add a lot of new methods, consider making a subclass
Downside: People from those other languages may be appalled
Solution: Ignore them
Next | Copyright © 1998 M-J. Dominus |