Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

compile or run-time inheritance

by sh1tn (Priest)
on Jun 17, 2006 at 14:22 UTC ( #555961=perlquestion: print w/ replies, xml ) Need Help??
sh1tn has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

Please let me know - when does the inheritence occur in perl? And if it's by default compile time, is there a way to be inforced to happen at run-time?


Comment on compile or run-time inheritance
Re: compile or run-time inheritance
by adrianh (Chancellor) on Jun 17, 2006 at 14:24 UTC
    Please let me know - when does the inheritence occur in perl? And if it's by default compile time, is there a way to be inforced to happen at run-time?

    Well - compile/run time is a very fuzzy divide with Perl. But yes - you can change the inheritance structure of objects at run time (e.g. by tweaking the @ISA of a package.)

Re: compile or run-time inheritance
by gellyfish (Monsignor) on Jun 17, 2006 at 14:44 UTC
Re: compile or run-time inheritance
by ioannis (Priest) on Jun 17, 2006 at 15:10 UTC
    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.
      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-12-22 00:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (110 votes), past polls