Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Would someone mind helping me understand this Perl OO code?

by romandas (Pilgrim)
on Dec 22, 2009 at 16:11 UTC ( [id://813916]=note: print w/replies, xml ) Need Help??


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?
  • Comment on Re^4: Would someone mind helping me understand this Perl OO code?

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-18 07:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found