refactor the case of abortive when()
Yuval Kogman [Mon, 31 Aug 2009 19:25:58 +0000 (22:25 +0300)]
lib/Try/Tiny.pm

index 5932535..477ef64 100644 (file)
@@ -65,9 +65,12 @@ sub try (&;$) {
                        for ($error) {
                                return $catch->($error);
                        }
-               } else {
-                       return;
+
+                       # in case when() was used without an explicit return, the C<for>
+                       # loop will be aborted and there's no useful return value
                }
+
+               return;
        } else {
                # no failure, $@ is back to what it was, everything is fine
                return $wantarray ? @ret : $ret[0];