http://qs1969.pair.com?node_id=813916


in reply to Re^3: Would someone mind helping me understand this Perl OO code?
in thread Would someone mind helping me understand this Perl OO code?

I'm sure this behavior is documented somewhere, but didn't see it. Do you know where it can be found?

Since new isn't a reserved word, how does perl know to pass the package name implicitly into that method in the first place? I could have just as badlyeasily named the constructor 'bargle'. Is the package name passed implicitly on every method call? Or just the one where the object is blessed?

Replies are listed 'Best First'.
Re^5: Would someone mind helping me understand this Perl OO code?
by almut (Canon) on Dec 22, 2009 at 16:16 UTC
    Do you know where it can be found?

    ...for example in perltoot (search for "Method Call" (case-sensitively)).

Re^5: Would someone mind helping me understand this Perl OO code?
by kennethk (Abbot) on Dec 22, 2009 at 16:18 UTC
    In perlboot, an intro to OO in Perl, it is discussed in The extra parameter of method invocation.

    Update: To answer your updated question, the package name or blessed object are passed in a method invocation whenever you use the The Arrow Operator to invoke a package method. So Node->new() will pass "Node" and new(), Node::new() or $code_ref->() would not.

Re^5: Would someone mind helping me understand this Perl OO code?
by ikegami (Patriarch) on Dec 22, 2009 at 16:18 UTC

    It's the first thing perlobj says about methods

    A Method is Simply a Subroutine

    Unlike say C++, Perl doesn't provide any special syntax for method definition. (It does provide a little syntax for method invocation though. More on that later.) A method expects its first argument to be the object (reference) or package (string) it is being invoked on.