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:
Then you can write code like this:sub accessor { my $self = shift; if (@_) { # Sets the attribute. $$self{key} = shift; return $self; } return $$self{key}; # Gets the attribute. }
my $obj->key1(value1) ->key2(value2) ->key3(value3);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: multiple method calls against the same object, revisited
by Aristotle (Chancellor) on Dec 28, 2004 at 22:30 UTC |
In Section
Cool Uses for Perl