What is the best way to deal with exceptions threw in a method chaining in Perl? I want to assign a value of 0 or undef if any of the methods chained throw an exception
Code sample:
my $x = $obj->get_obj->get_other_obj->get_another_obj->do_something;
What the best way to do it? Do I have to wrap in a try/catch/finally statement everytime? The context I want to apply this is: Im working in web development using Catalyst and DBIC and I do a lot of chained resultsets and if some of this resultset throw an exception I just want to assign a value of 0 or undef and then treat this error in the template (Im using Template Toolkit). If there is another way to do that without wrapping every call in try/catch, please let me know. If you know a better way to treat this type of error in the same context (Catalyst/DBIC/TT), please suggest. A practical example would be when the user search for something and this does not exists.
$foo->Name("David") will set the name to
David, and
$foo->Name` will return the current name. Thus, a null return from one method might be a valid input to another method. – Undesirable