Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^6: perl inheritance

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

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

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?

Replies are listed 'Best First'.
Re^7: perl inheritance
by tobyink (Abbot) on Mar 24, 2012 at 13:12 UTC

    Very little advantage in this case. It just so happens that in the same loop I'm also playing around with @ISA and past experience has taught me to alter @ISA as early as possible. Modern versions of Perl are pretty smart when it comes to invalidating method resolution caches, but force of habit makes me put any @ISA alteration in a BEGIN block unless there's a good reason not to.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Well, I can imagine putting assignments to @ISA in a BEGIN block if you have the habit of putting other things in a BEGIN block.

      I typically have my assignment to @ISA near the top of the file, before any method calls are done. And that never is a problem.

      Perl has always tried to invalidate method caches on assignment to @ISA -- although in a dim past, there was a bug preventing this to happen. This was fixed in 5.004 or 5.005. Long enough ago to not care about anymore. Not that method cache has any reason to be relevant here; for that to be relevant, we need to have something like:

      • Assign to @ISA.
      • Call a method "X".
      • Assign to @ISA so X resolves to a *different* sub.
      • Call method "X" again.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961334]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2018-07-23 17:03 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (472 votes). Check out past polls.