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

Re: curried-up moose

by Jenda (Abbot)
on Jan 21, 2009 at 23:42 UTC ( [id://737991]=note: print w/replies, xml ) Need Help??


in reply to curried-up moose

Waitasecond. Assuming you did not intend to say that the legs have some eyes, you want the $body->legs(...) to return the modified $body, right? So the $body->eyes will return the $body as well, right? So the $body->eyes->color returns the color of the body, not the color of the eyes, right? I guess not...

So what does the $body->method(...) return? The modified $body or some inner object? Or sometimes one and sometimes the other?

Method chaining works OK on objects that do not have any inner objects and whose method names make it very very clear which ones modify the object (and then return the modified $self) and which ones return some properties. As soon as it's not entirely clear, you're gonna run into problems.

Maybe it would be better to use somethign like this instead:

for ($body) { $_->legs(size=>42); $_->eyes(color => 'blue'); print $_->eyes->color; }
(This is similar to the with(object) { .method(...); .method(...) } of some languages.)

It's kinda shame you can't use something like

for ($body) { -->legs(size=>42); -->eyes(color => 'blue'); print -->eyes->color; }
as that would be easy to write and I think it would not clash with anything.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found