princepawn has asked for the wisdom of the Perl Monks concerning the following question:

I was carousing thru the BIVIO Webapp System and noticed this
__PACKAGE__->compile([ HOME => [ 1, ], WORK => [ 2, ], ]);
I would appreciate knowing (a) what this does (b) where this is documented in the Perl manpages.

Replies are listed 'Best First'.
Re: __PACKAGE__-compile .. what in the world is this?
by rjray (Chaplain) on Feb 19, 2002 at 06:45 UTC

    What this does is uses the special token __PACKAGE__ to invoke a static (class) method called compile() with the arguments you see there. Specifically, an array reference with four elements.

    The __PACKAGE__ token yields the current package that the interpreter is executing in (this wording is kind of cramped, I realize, but I can't think of a better way to say it right now). If the interpreter encounters it in an inherited method from within a subclass, it will yield that subclasses name. What this means is, a method in an intended base-class can write this as a way of invoking compile as a method, without using an actual object reference. It's still treated as a method invocation, and uses the @ISA search path of the actual (sub)class, not the original class from which it was derived.

    --rjray

Re (tilly) 1: __PACKAGE__-compile .. what in the world is this?
by tilly (Archbishop) on Feb 19, 2002 at 07:29 UTC
    Others have answered the "what". Here is the where.

    __PACKAGE__ is defined in perldata.

    After you understand that __PACKAGE__ will be replaced with the current package, the workings of the method call are described in perlobj and elsewhere.

    To discover this yourself, along with the other references to __PACKAGE__, try:

    perldoc -l perl
    to find what directory perl.pod is in, cd to that directory, and then grep for __PACKAGE__.

    UPDATE
    Oops. Kanji pointed out that his post did answer the where. But the idea of using grep is still worth knowing about as a way to find these things out when you don't know where to look first.

Re: __PACKAGE__-compile .. what in the world is this?
by Kanji (Parson) on Feb 19, 2002 at 06:43 UTC
princepawn writes a book?
by Anonymous Monk on Feb 19, 2002 at 22:08 UTC

    In your journal, you mention a DBI book offer. I think you have a lot of good knowledge, but you often seem confused on basic concepts like the one above. I do not think you are ready to write that book. Maybe it is just luck that I happen to know what __PACKAGE__ is for, but you have already encountered it and did not notice. Why do you pose as an expert when you miss things like this?

    In your debates with chromatic, you repeatedly misunderstand the points of the argument in question and you have called vroom an asshole. You've compared Perlmonks to a religious cult. How can I take you seriously? When you can convince me that you are worth listening to, I will listen.