in reply to Re: curried-up moose
in thread curried-up moose
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):
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: curried-up moose
by pobocks (Chaplain) on Jan 22, 2009 at 07:35 UTC |
In Section
Seekers of Perl Wisdom