diff options
Diffstat (limited to 't/try/lib')
-rw-r--r-- | t/try/lib/Error1.pm | 14 | ||||
-rw-r--r-- | t/try/lib/Error2.pm | 14 | ||||
-rw-r--r-- | t/try/lib/Try.pm | 53 |
3 files changed, 81 insertions, 0 deletions
diff --git a/t/try/lib/Error1.pm b/t/try/lib/Error1.pm new file mode 100644 index 0000000..eb2d62a --- /dev/null +++ b/t/try/lib/Error1.pm @@ -0,0 +1,14 @@ +package Error1; +use strict; +use warnings; + +use Try; + +try { +} +catch { +} +finallyy { +} + +1; diff --git a/t/try/lib/Error2.pm b/t/try/lib/Error2.pm new file mode 100644 index 0000000..242bdc6 --- /dev/null +++ b/t/try/lib/Error2.pm @@ -0,0 +1,14 @@ +package Error2; +use strict; +use warnings; + +use Try; + +try { +} +finally { +} +catch { +} + +1; diff --git a/t/try/lib/Try.pm b/t/try/lib/Try.pm new file mode 100644 index 0000000..372f10e --- /dev/null +++ b/t/try/lib/Try.pm @@ -0,0 +1,53 @@ +package Try; +use strict; +use warnings; + +use Try::Tiny (); + +use Parse::Keyword { try => \&try_parser }; +use Exporter 'import'; + +our @EXPORT = ('try'); + +sub try { + my ($try, $catch, $finally) = @_; + + &Try::Tiny::try( + $try, + ($catch ? (&Try::Tiny::catch($catch)) : ()), + ($finally ? (&Try::Tiny::finally($finally)) : ()), + ); +} + +sub try_parser { + my ($try, $catch, $finally); + + lex_read_space; + + die "syntax error" unless lex_peek_unichar eq '{'; + $try = parse_block; + + lex_read_space; + + ensure_linestr_len(5); + if (linestr =~ /^catch/) { + lex_read_to(5); + lex_read_space; + die "syntax error" unless lex_peek_unichar eq '{'; + $catch = parse_block; + } + + lex_read_space; + + ensure_linestr_len(7); + if (linestr =~ /^finally/) { + lex_read_to(7); + lex_read_space; + die "syntax error" unless lex_peek_unichar eq '{'; + $finally = parse_block; + } + + return (sub { ($try, $catch, $finally) }, 1); +} + +1; |