Created
May 19, 2012 08:02
-
-
Save koorchik/2729994 to your computer and use it in GitHub Desktop.
Try::Tiny with helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ... | |
| test_exception( Exception1->new() ); | |
| test_exception( Exception2->new() ); | |
| test_exception( Exception3->new() ); | |
| test_exception("Special text\n"); | |
| test_exception("Text exception\n"); | |
| use Scalar::Util qw/blessed/; | |
| sub e($) { | |
| my $class = shift; | |
| my $e = $_; | |
| return unless blessed($e); | |
| return $e->isa($class); | |
| } | |
| sub test_exception { | |
| my $e = shift; | |
| try { | |
| die $e; | |
| } | |
| catch { | |
| when ( e 'Exception1') { | |
| say ref($_) . " matches Exception1"; | |
| } | |
| when ( e 'Exception2' ) { | |
| say ref($_) . " matches Exception2"; | |
| } | |
| when ( e 'Exception::Base' ) { | |
| say ref($_) . " matches Exception::Base"; | |
| } | |
| when (/Special/) { | |
| chomp; | |
| say qq{"$_" matches qr/Special/}; | |
| } | |
| default { | |
| chomp; | |
| say qq{"$_" matches default}; | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment