File Coverage

blib/lib/Babble/Plugin/SKT.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 0 2 0.0
total 23 25 92.0


line stmt bran cond sub pod time code
1             package Babble::Plugin::SKT;
2              
3 1     1   71230 use Moo;
  1         7456  
  1         5  
4              
5             sub extend_grammar {
6 1     1 0 1809 my ($self, $g) = @_;
7 1         8 $g->add_rule(TryCatch =>
8             'try(?&PerlOWS)(?&PerlBlock)'
9             .'(?:(?&PerlOWS)catch(?&PerlOWS)(?&PerlBlock))?+'
10             );
11 1         7 $g->augment_rule(Statement => '(?&PerlTryCatch)');
12             }
13              
14             sub transform_to_plain {
15 3     3 0 1735 my ($self, $top) = @_;
16 3         15 $top->remove_use_statement('Syntax::Keyword::Try');
17             $top->each_match_within(TryCatch => [
18             'try(?&PerlOWS)', [ try_block => '(?&PerlBlock)' ],
19             '(?:(?&PerlOWS)catch(?&PerlOWS)', [ catch_block => '(?&PerlBlock)' ], ')?+'
20             ] => sub {
21 3     3   8 my ($m) = @_;
22 3         16 my ($try, $catch) = $m->subtexts(qw(try_block catch_block));
23 3         9 my $text = do {
24 3 100       20 if ($catch) {
25 1         7 $try =~ s/\s*}$/; 1 }/;
26 1         5 'unless (eval '.$try.') '.$catch;
27             } else {
28 2         7 'eval '.$try;
29             }
30             };
31 3         23 $m->replace_text('{ local $@; '.$text.' }');
32 3         59 });
33             }
34              
35             1;
36             __END__
37              
38             =head1 NAME
39              
40             Babble::Plugin::SKT - Plugin to convert Syntax::Keyword::Try to eval
41              
42             =head1 SEE ALSO
43              
44             L<Syntax::Keyword::Try>
45              
46             =cut