Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: perl inheritance

by JavaFan (Canon)
on Mar 23, 2012 at 18:26 UTC ( #961278=note: print w/ replies, xml ) Need Help??

in reply to perl inheritance

Is there a way to accomplish this without overriding all the base class methods?
That depends on how the superclass has implemented the methods.

But you may be able to do something like:

foreach my $method (... list of methods to override ...) { eval <<"EOT"; sub $method { my (\$self, \@args) = \@_; my $result = \$self->SUPER::$method(\@args); bless \$result, __PACKAGE__; \$result; } EOT }

Comment on Re: perl inheritance
Download Code
Replies are listed 'Best First'.
Re^2: perl inheritance
by Anonymous Monk on Mar 23, 2012 at 18:38 UTC

    This is *very* interesting... Thank you! Would this be invoked in the constructor of the derived class?

      Would this be invoked in the constructor of the derived class?
      Of course not! This is something you need to be done once, and on class level. So, you'd do it outside of any method. That way, it get executed when you use the module.
        This smells like a good place for an import method.. What do you think? thanks!

        this smells like it should go in an import method? What do you think ?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961278]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2015-10-04 20:51 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (104 votes), past polls