Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: chaining method calls

by mirod (Canon)
on Jun 11, 2003 at 23:16 UTC ( #265217=note: print w/ replies, xml ) Need Help??


in reply to chaining method calls

I actually love chaining methods (I changed a whole lot of methods in XML::Twig so they would return something that can be chained).

What's not to love about being able to write:

... # handler for warning warning => sub { $_->change_tag( 'p') ->set_att( style => "color:red") ->set_prefix( "WARNING: "); }, ...

(apart from the fact that you could do all of this with CSS of course ;--) ?

I agree that sometimes it can get a little confusing though, when the returned object/value is not obvious: should $elt->delete_atts return the element, so you can chain method calls on it, or should it return the attribute hash so you can store it?

Overall I think it makes for elegant code. You'll get use to it ;--)


Comment on Re: chaining method calls
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2015-08-01 01:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls