summaryrefslogtreecommitdiffstats
path: root/t/try/lib/Try.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-07-19 02:02:33 -0400
committerJesse Luehrs <doy@tozt.net>2013-07-19 02:02:33 -0400
commitbe8cfb28cb18499cf6ddfff9eff256d08537dd18 (patch)
tree375f7525e6ee6f39d1ed952edb4be17c88c9a0f6 /t/try/lib/Try.pm
parent56de12a2999763ca14aefdf4ac1af1d527ccbc71 (diff)
downloadparse-keyword-be8cfb28cb18499cf6ddfff9eff256d08537dd18.tar.gz
parse-keyword-be8cfb28cb18499cf6ddfff9eff256d08537dd18.zip
add some (failing) tests
Diffstat (limited to 't/try/lib/Try.pm')
-rw-r--r--t/try/lib/Try.pm53
1 files changed, 53 insertions, 0 deletions
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;