Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: curried-up moose

by pobocks (Chaplain)
on Jan 18, 2009 at 02:53 UTC ( #737106=note: print w/replies, xml ) Need Help??


in reply to curried-up moose

I'm a little confused by:

$body = $body->legs( size=>42 )->eyes( color => blue);
I mean, why do the legs make the eyes, knowhutimean?

for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";

Replies are listed 'Best First'.
Re^2: curried-up moose
by Limbic~Region (Chancellor) on Jan 21, 2009 at 19:59 UTC
    pobocks,
    There is heated debate regarding chained methods as well as a method returning a reference to the object (good idea or not) but it works like this (traditional perl OO):
    sub legs { my ($self, $attribute, $val) = @_; $self->{legs}{$attribute} = $val; return $self; } sub eyes { my ($self, $attribute, $val) = @_; $self->{eyes}{$attribute} = $val; return $self; }

    In other words, the method returns the object so you can then invoke another method on the return value and then assign the return value of that chained method back to the original scalar holding a reference to the object. I made minor updates to this node soon after submitting as I hadn't seen the original code in the root thread.

    Cheers - L~R

      That is a remarkably clear summary, and you may consider me up to speed, and thankful for the explanation.

      I can see why there is debate over this; it seems vaguely distasteful to me, because it means that the code doesn't match the mental model of the thing it's modeling. On the other hand, the savings in typing must certainly make it attractive to many.

      for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-12-03 19:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?