Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: __PACKAGE__ interpolated before inheritence

by wog (Curate)
on Dec 08, 2001 at 19:22 UTC ( #130417=note: print w/replies, xml ) Need Help??


in reply to __PACKAGE__ interpolated before inheritence

If you want the id method to always return the package the object is blessed to you could just use ref:

sub id { ref $_[0] }

Replies are listed 'Best First'.
Re: Re: __PACKAGE__ interpolated before inheritence
by Beatnik (Parson) on Dec 08, 2001 at 19:32 UTC
    Not always but close enough :) I'm confused why __PACKAGE__ wont work.

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
      __PACKAGE__ is turned into, at compile time, the current package when it is compiled. (That is, the one established by package statements.)
        To see this in action:
        % perl -MO=Deparse -e 'use constant Y => "foo"; $x="bar"; return __PAC +KAGE__, $x, Y' sub Y () { package constant; $scalar; } $x = 'bar'; return 'main', $x, 'foo'; # <=== inlined values at compile time...
        Notice that __PACKAGE__ and the constant Y got inlined at compile time, whereas $x did not.

        -Blake

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2022-11-26 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?