| 1 | package Syntax::Feature::Try; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 27 | ▶ | use 5.014; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 27 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 27 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 27 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 27 | ▶ | use XSLoader; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 27 | ▶ | use Scalar::Util qw/ blessed /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 27 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 27 | our $VERSION = '1.005'; | |||||||||||||||||||||||||||
| 12 | 27 | XSLoader::load(); | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 27 | my @custom_exception_matchers; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 57 | ▶ | sub install { | ||||||||||||||||||||||||||
|
Subroutine
install: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 57 | $^H{+HINTKEY_ENABLED} = 1; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | sub uninstall { | ||||||||||||||||||||||||||
|
Subroutine
uninstall: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 1 | $^H{+HINTKEY_ENABLED} = 0; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 7 | ▶ | sub register_exception_matcher { | ||||||||||||||||||||||||||
|
Subroutine
register_exception_matcher: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 26 | 7 | my ($code_ref) = @_; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 7 | ▶ | if (ref($code_ref) ne 'CODE') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 3 | croak "Invalid parameter: expected CODE reference."; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | if (not grep { $_ == $code_ref } @custom_exception_matchers) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 2 | push @custom_exception_matchers, $code_ref; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # only for tests: | ||||||||||||||||||||||||||||
| 38 | 3 | ▶ | sub _custom_exception_matchers { @custom_exception_matchers } | ||||||||||||||||||||||||||
|
Subroutine
_custom_exception_matchers: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # TODO convert "our" to "my" variables | ||||||||||||||||||||||||||||
| 41 | 27 | our $is_end_of_block; | |||||||||||||||||||||||||||
| 42 | 27 | our $return_values; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 270 | ▶ | sub _statement { | ||||||||||||||||||||||||||
|
Subroutine
_statement: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||
| 45 | 270 | my ($try_block, $catch_list, $finally_block) = @_; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 270 | my $stm_handler = bless {finally => $finally_block}, __PACKAGE__; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 270 | local $@; | |||||||||||||||||||||||||||
| 50 | 270 | local $is_end_of_block; | |||||||||||||||||||||||||||
| 51 | 270 | my $exception = run_block($stm_handler, $try_block, 1); | |||||||||||||||||||||||||||
| 52 | 269 | ▶ | if ($exception and $catch_list) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$exception and $catch_list
MC/DC100%2/2
$exception and $catch_list
$exception
$catch_list
Truth table100%3/3
A and B
A= $exceptionB= $catch_list
| |||||||||||||||||||||||||||||
| 53 | 137 | my $catch_block = _get_exception_handler($exception, $catch_list); | |||||||||||||||||||||||||||
| 54 | 137 | ▶ | if ($catch_block) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 136 | local $is_end_of_block; | |||||||||||||||||||||||||||
| 56 | 136 | $exception = run_block($stm_handler, $catch_block, 1, $exception); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 269 | ▶ | if ($finally_block) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 166 | delete $stm_handler->{finally}; | |||||||||||||||||||||||||||
| 62 | 166 | local $is_end_of_block; | |||||||||||||||||||||||||||
| 63 | 166 | run_block($stm_handler, $finally_block); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 267 | ▶ | if ($exception) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 11 | _rethrow($exception); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 256 | $return_values = $stm_handler->{return}; | |||||||||||||||||||||||||||
| 71 | 256 | return $stm_handler->{return}; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 270 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 75 | 270 | my ($self) = @_; | |||||||||||||||||||||||||||
| 76 | 270 | local $is_end_of_block; | |||||||||||||||||||||||||||
| 77 | 270 | ▶ | run_block($self, $self->{finally}) if $self->{finally}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 137 | ▶ | sub _get_exception_handler { | ||||||||||||||||||||||||||
|
Subroutine
_get_exception_handler: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 81 | 137 | my ($exception, $catch_list) = @_; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 137 | foreach my $item (@{ $catch_list }) { | |||||||||||||||||||||||||||
| 84 | 176 | my ($block_ref, @args) = @$item; | |||||||||||||||||||||||||||
| 85 | 176 | ▶ | return $block_ref if _exception_match_args($exception, @args); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 176 | ▶ | sub _exception_match_args { | ||||||||||||||||||||||||||
|
Subroutine
_exception_match_args: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 90 | 176 | my ($exception, $className) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 176 | ▶ | return 1 if not defined $className; # without args catch all exceptions | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 153 | foreach my $matcher (@custom_exception_matchers) { | |||||||||||||||||||||||||||
| 95 | 10 | my $result = $matcher->($exception, $className); | |||||||||||||||||||||||||||
| 96 | 10 | ▶ | return $result if defined $result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 146 | ▶ | if (Moose::Util::TypeConstraints->can('find_type_constraint')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 7 | my $type = Moose::Util::TypeConstraints::find_type_constraint($className); | |||||||||||||||||||||||||||
| 101 | 7 | ▶ | return $type->check($exception) if $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 139 | ▶ | return blessed($exception) && $exception->isa($className); | ||||||||||||||||||||||||||
|
Condition100%3/3
builtin::blessed($exception) && $exception->isa($className)
MC/DC100%2/2
builtin::blessed($exception) && $exception->isa($className)
builtin::blessed($exception)
$exception->isa($className)
Truth table100%3/3
A && B
A= builtin::blessed($exception)B= $exception->isa($className)
| |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 11 | ▶ | sub _rethrow { | ||||||||||||||||||||||||||
|
Subroutine
_rethrow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 108 | 11 | die (@_); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 272 | ▶ | sub _set_is_end_of_block { | ||||||||||||||||||||||||||
|
Subroutine
_set_is_end_of_block: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 112 | 272 | $is_end_of_block = 1; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 142 | ▶ | sub _get_return_value { | ||||||||||||||||||||||||||
|
Subroutine
_get_return_value: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 116 | 142 | my $return = $return_values; | |||||||||||||||||||||||||||
| 117 | 142 | undef $return_values; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 142 | ▶ | return wantarray ? @$return : $return->[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 27 | 1; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | __END__ | ||||||||||||||||||||||||||||