How do I handle errors in methods chains in Perl?

后端 未结 3 808
谎友^
谎友^ 2021-02-04 12:06

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

3条回答
  •  再見小時候
    2021-02-04 12:49

    One idea would be to create a class that uses overload to return a false value when an instance object is evaluated in string/number/boolean contexts, but would still allow methods to be called on it. An AUTOLOAD method could always return $self allowing a method chain to propagate the same error.

提交回复
热议问题