Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: compile or run-time inheritance

by ioannis (Priest)
on Jun 17, 2006 at 15:10 UTC ( #555977=note: print w/ replies, xml ) Need Help??


in reply to compile or run-time inheritance

You cannot have binding of methods before INIT because the type of invocant is determined at runtime. For example, when we bless a reference with bless {}, $string, this executes at runtime to assign the class type, which tells us which @ISA to examine.


Comment on Re: compile or run-time inheritance
Re^2: compile or run-time inheritance
by adrianh (Chancellor) on Jun 18, 2006 at 09:13 UTC
    You cannot have binding of methods before INIT because the type of invocant is determined at runtime

    I beg to differ :-)

    #! /usr/bin/perl use strict; use warnings; INIT { print "in INIT\n"; print "out INIT\n"; } BEGIN { print "in BEGIN\n"; { package Foo; sub new { bless {}, shift }; sub foo { print "I'm a ", shift, "\n"}; } Foo->new->foo; print "out BEGIN\n"; } __END__ in BEGIN I'm a Foo=HASH(0x181af90) out BEGIN in INIT out INIT
      Oh, come on! The issue with BEGIN has already been mentioned in previous posts. This love of accuracy we omit because it adds nothing to the core discussion.

        Well, it just turned out that you were wrong. There's nothing special about INIT or BEGIN when it comes to inheritance. Inheritance just requires that @ISA have been set at some time prior to when an @ISA-using operation is executing. It's an utter red herring. If a person is stuck with making the change occur "earlier" they can always say BEGIN { @ISA = ... } or use base ...; both of which push that bit of @ISA setting as early as possible for that little snippet of code.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        Oh, come on! The issue with BEGIN has already been mentioned in previous posts. This love of accuracy we omit because it adds nothing to the core discussion.

        And saying completely inaccurate statements like "You cannot have binding of methods before INIT" does add to the core discussion? How exactly? Especially when the OP is asking specifically about whether Perl handles things differently at "compile" and "run" time - to which the answer is no. It doesn't.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-07-31 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (248 votes), past polls