Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: perl inheritance

by Anonymous Monk
on Mar 23, 2012 at 18:38 UTC ( #961283=note: print w/replies, xml ) Need Help??

in reply to Re: perl inheritance
in thread perl inheritance

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


Replies are listed 'Best First'.
Re^3: perl inheritance
by JavaFan (Canon) on Mar 23, 2012 at 19:10 UTC
    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!

        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'
        Sounds like a bad idea to me. Why do you think that's a good idea?

      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://961283]
[james28909]: id just rename the subrouties perl what kind of data they are getting. something easy to remember too. like if get_data were returning movies titles, rename get_data to movies or movie_titles or get_movie_titles.
[james28909]: s/perl/per/
[james28909]: but i dont really know what your end goal is. if it works dont fix it lol
[Lady_Aleena]: james28909, I use get_data in a subroutine called movies.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-05-24 04:32 GMT
Find Nodes?
    Voting Booth?