P is for Practical | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I wrote MyBaseClass.pm to avoid having to write methods for each hash item in the derived classes. Amazingly, it works as I intended. In this example, Address.pm inherits the new method from MyBaseClass.pm and the state method is handled in the AUTOLOAD sub in MyBaseClass.pm. This allows me to call state as a method <nobr>(print $c->state)</nobr> and avoid accessing the object's hash directly with <nobr>print $c->{address}{state}</nobr>. Further it will return undef if the method doesn't exist, allowing me to test for an additional address line, for example. I'm wondering if there is something I'm not anticipating. Is there a problem with this approach that I don't see or am I just paranoid? testing.pl
MyBaseClass.pm
Address.pm
HTH, Charles K. Clarkson In reply to Am I asking for trouble with my own AUTOLOAD sub? by CharlesClarkson
|
|