transformed.pl untested

filter: Statementstmt 0.0% 0 / 93 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 152 CC 9 SCAR 40.7
CC
9
Cov
0%
foo
90.0
BEGIN
2.0
BEGIN
2.0
CRAP 58.6
1 #!/usr/bin/env perl
2 #
3 # To get the filtered code, try this:
4 # perl -c -MFilter::ExtractSource test.pl | grep -v '^use Try::Harder;'
5 #
6 use strict;
7 use warnings;
8 use lib './lib';
9 use Try::Harder;
10 use Data::Dumper;
11  
12 print "BEGIN\n";
13  
14 sub foo {
15 my $z = 1;
16 ;{ local $Try::Harder::TRY = sub { do {
17 print "TRYING\n";
18 #return "YAAY!";
19 my $z = 8;
20 die "EXCEPTION $z \n";
21 }; return $Try::Harder::SENTINEL; };
22 local $Try::Harder::CATCH = sub { do {
23 print "CAUGHT: $@";
24 $z = 7;
25 # should return this value from the sub
26 #return "YAAY!!"
27 }; return $Try::Harder::SENTINEL; };
28 local $Try::Harder::FINALLY = 'Try::Harder::ScopeGuard'->_new(sub {
29 # should always output
30 print "FINALLY, [$@]\n";
31 # finally doesn't support return
32 return "IMPOSSIBLE!"
33 }, @_); local ( $Try::Harder::ERROR, $Try::Harder::DIED, @Try::Harder::RETVAL ); local $Try::Harder::WANTARRAY = wantarray; { local $@; $Try::Harder::DIED = not eval { if ( $Try::Harder::WANTARRAY ) { @Try::Harder::RETVAL = &$Try::Harder::TRY; } elsif ( defined $Try::Harder::WANTARRAY ) { $Try::Harder::RETVAL[0] = &$Try::Harder::TRY; } else { &$Try::Harder::TRY; } return 1; }; $Try::Harder::ERROR = $@; }; if ( $Try::Harder::DIED ) { if ( $Try::Harder::CATCH ) { local $@ = $Try::Harder::ERROR; if ( $Try::Harder::WANTARRAY ) { @Try::Harder::RETVAL = &$Try::Harder::CATCH; } elsif ( defined $Try::Harder::WANTARRAY ) { $Try::Harder::RETVAL[0] = &$Try::Harder::CATCH; } else { &$Try::Harder::CATCH; } } else { die $Try::Harder::ERROR } }; if ( caller() and (!ref($Try::Harder::RETVAL[0]) or !$Try::Harder::RETVAL[0]->isa('Try::Harder::SENTINEL')) ) { return $Try::Harder::WANTARRAY ? @Try::Harder::RETVAL : $Try::Harder::RETVAL[0]; } }
34 print "\$z = $z\n";
35 print "OOPS! $@\n";
36 return "FAIL";
37 }
38  
39 my $x = foo();
40 print "RETURNED: " . Dumper $x;
41  
42 # returning from outside a sub makes no sense.
43 #try { print "TRYING AGAIN\n"; } #die "EXCEPTION\n" }
44 ;{ local $Try::Harder::TRY = sub { do { print "TRYING AGAIN\n"; }; return $Try::Harder::SENTINEL; };
45 local $Try::Harder::CATCH = sub { do { print "CAUGHT: $@\n" }; return $Try::Harder::SENTINEL; };
46 local $Try::Harder::FINALLY = 'Try::Harder::ScopeGuard'->_new(sub { print "FINALLY: CAUGHT [$@]\n" }, @_); local ( $Try::Harder::ERROR, $Try::Harder::DIED, @Try::Harder::RETVAL ); local $Try::Harder::WANTARRAY = wantarray; { local $@; $Try::Harder::DIED = not eval { if ( $Try::Harder::WANTARRAY ) { @Try::Harder::RETVAL = &$Try::Harder::TRY; } elsif ( defined $Try::Harder::WANTARRAY ) { $Try::Harder::RETVAL[0] = &$Try::Harder::TRY; } else { &$Try::Harder::TRY; } return 1; }; $Try::Harder::ERROR = $@; }; if ( $Try::Harder::DIED ) { if ( $Try::Harder::CATCH ) { local $@ = $Try::Harder::ERROR; if ( $Try::Harder::WANTARRAY ) { @Try::Harder::RETVAL = &$Try::Harder::CATCH; } elsif ( defined $Try::Harder::WANTARRAY ) { $Try::Harder::RETVAL[0] = &$Try::Harder::CATCH; } else { &$Try::Harder::CATCH; } } else { die $Try::Harder::ERROR } }; if ( caller() and (!ref($Try::Harder::RETVAL[0]) or !$Try::Harder::RETVAL[0]->isa('Try::Harder::SENTINEL')) ) { return $Try::Harder::WANTARRAY ? @Try::Harder::RETVAL : $Try::Harder::RETVAL[0]; } }
47  
48 print "END\n";
49  
50