http://www.perlmonks.org?node_id=417738


in reply to multiple method calls against the same object, revisited

I prefer "fixing" this at the source. I tend to have methods that are purely called for their side-effects, and not for their return values, return the object they acted upon.

And that includes accessors. Tk does it that way as well, and I like it. Example:

sub accessor { my $self = shift; if (@_) { # Sets the attribute. $$self{key} = shift; return $self; } return $$self{key}; # Gets the attribute. }
Then you can write code like this:
my $obj->key1(value1) ->key2(value2) ->key3(value3);