Performance of chained methods.
Michael Stillwell
mjs at beebo.org
Wed Oct 30 07:25:39 CST 2002
On Wednesday, Oct 30, 2002, at 14:48 Australia/Melbourne, Scott Penrose
wrote:
> my $ref = eval
> {SomeClass->FirstMethod($param1)->AnotherMethod($param2)-
> >MoreMethods();};
> return undef if ($@);
>
> Or is that a really bad practice?, is there a better way ?,
That does seem to be the best way, although I do feel your unease...
I suppose in some circumstances it might make sense to modify the
methods so that they never return undef but that won't always be
convenient. (Perhaps if the methods are tree operations that operate
on sets, then children() could return a null set instead of undef, say,
if there were no children.) You don't get any short-circuiting this
way though.
--M.
* * *
http://beebo.org
More information about the Melbourne-pm
mailing list