http://qs321.pair.com?node_id=130417


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