Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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 }

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2018-04-25 12:48 GMT
Find Nodes?
    Voting Booth?