in reply to Return $self, but what if I don't wanna?
or evensub calculate_foo { my $self = shift; $self->foo($self->foo + 999); return $self->foo; }
will work just fine.sub calculate_foo { my $self = shift; return $self->foo($self->foo + 999); }
2) Question not relevant because answer to #1 was "yes".
3) It makes sense when it makes sense.
OK, less tautologically, it makes sense to return something other than the object when something other than the object is what will typically be most useful to the caller. If you're doing a calculation, return its result; if you're creating an aggregated object, return that one; etc.
|
|---|