Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^3: perl inheritance

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

in reply to Re^2: perl inheritance
in thread perl inheritance

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.

Replies are listed 'Best First'.
Re^4: perl inheritance
by Anonymous Monk on Mar 23, 2012 at 20:21 UTC
    This smells like a good place for an import method.. What do you think? thanks!

      No, I wouldn't put it in an import module. A BEGIN block would be better. If you put it in import, you have no guarantee that the import method will ever actually be called. It's quite easy to load a module without ever calling the import method. Conversely, it's very easy for the import method to get called multiple times.

      I actually do something pretty similar to the technique being discussed in XML::LibXML::Augment.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
        What's the advantage of using a BEGIN block for that? Do you really think there's something to gain putting those methods in place, before the other methods are compiled?
      Sounds like a bad idea to me. Why do you think that's a good idea?
Re^4: perl inheritance
by Anonymous Monk on Mar 23, 2012 at 20:35 UTC

    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://961291]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2018-01-20 00:25 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (226 votes). Check out past polls.