Unexpected/TraitFor/Throwing.pm

filter: Statementstmt 100% 58 / 58 Branchbran 100% 19 / 20 (1 uncoverable) Conditioncond 100% 5 / 5 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 16 / 16 Podpod 100% 4 / 4 totaltotal 100% 105 / 106 (1 uncoverable) CC 13 SCAR 9.2
CC
13
Cov
100%
caught
5.0
__ANON__
3.0
clone
3.0
CRAP 2.5
« Unexpected/TraitFor/ErrorLeader.pm ↑ Summary Unexpected/Types.pm »
1 package Unexpected::TraitFor::Throwing;
2  
3 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Carp ( );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Unexpected::Functions qw( is_one_of_us parse_arg_list );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Unexpected::Types qw( Maybe Object );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 requires qw( BUILD );
13  
14 # Private functions
15 61 ▶my $_cache_key = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
16 # uncoverable branch true
17 61 ▶ return $PID.'-'.(exists $INC{ 'threads.pm' } ? threads->tid() : 0);
Branch: 1 branch
BranchTrueFalseTotal
exists $INC{'threads.pm'} ? : 0 61 61
18 4 };
19  
20 4 my $_exception_cache = {};
21  
22 # Public attributes. Lifted from Throwable
23 has 'previous_exception' => is => 'ro', isa => Maybe[Object],
24 26 ▶ builder => sub { $_exception_cache->{ $_cache_key->() } };
Subroutine _build_previous_exception: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
25  
26 # Construction
27 31 ▶after 'BUILD' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
28 31 my $self = shift; my $e = $self->clone; delete $e->{previous_exception};
29  
30 31 $_exception_cache->{ $_cache_key->() } = $e;
31  
32 31 return;
33 4 };
34  
35 # Private methods
36 40 ▶my $_is_object_ref = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
37 40 ▶ my ($self, @args) = @_; blessed $self or return 0;
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($self) or return 0 3 37 40
38  
39 3 ▶ scalar @args and Carp::confess
Branch: 1 branch
BranchTrueFalseTotal
scalar @args and Carp::confess("Trying to throw an Exception object with arguments") 1 2 3
40 'Trying to throw an Exception object with arguments';
41 2 return 1;
42 4 };
43  
44 # Public methods
45 10 ▶sub caught {
Subroutine caught: called CC=5 SCAR=16.1
Pod documented
46 10 my ($self, @args) = @_;
47  
48 10 ▶ $self->$_is_object_ref( @args ) and return $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->$_is_object_ref(@args) and return $self 1 9 10
49  
50 9 my $attr = parse_arg_list @args;
51 9 ▶ my $error = $attr->{error} ||= $EVAL_ERROR; $error or return;
Branch: 1 branch
BranchTrueFalseTotal
$error or return 8 1 9
Condition100%3/3
$attr->{"error"} ||= $Unexpected::TraitFor::Throwing::EVAL_ERROR
l!l&&r!l&&!r
351
MC/DC100%2/2
$attr->{"error"} ||= $Unexpected::TraitFor::Throwing::EVAL_ERROR
$attr->{"error"} $Unexpected::TraitFor::Throwing::EVAL_ERROR
Truth table100%3/3
A ||= B
A= $attr->{"error"}B= $Unexpected::TraitFor::Throwing::EVAL_ERROR
ABresult
1X1
011
000
52  
53 8 ▶ return (is_one_of_us $error) ? $error : $self->new( $attr );
Branch: 1 branch
BranchTrueFalseTotal
&is_one_of_us($error) ? : 3 5 8
54 }
55  
56 33 ▶sub clone {
Subroutine clone: called CC=3 SCAR=11.0
Pod documented
57 33 my ($self, $args) = @_;
58  
59 33 ▶ my $class = blessed $self or $self->throw( 'Clone is an object method' );
Branch: 1 branch
BranchTrueFalseTotal
my $class = builtin::blessed($self) or $self->throw("Clone is an object method") 32 1 33
60  
61 32 ▶ return bless { %{ $self }, %{ $args // {} } }, $class;
Condition100%2/2
$args // {}
l!l
131
MC/DC100%1/1
$args // {}
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
62 }
63  
64 30 ▶sub throw {
Subroutine throw: called CC=3 SCAR=11.0
Pod documented
65 30 my ($self, @args) = @_;
66  
67 30 ▶ $self->$_is_object_ref( @args ) and die $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->$_is_object_ref(@args) and die $self 1 28 29
68 28 ▶ is_one_of_us $args[ 0 ] and die $args[ 0 ];
Branch: 1 branch
BranchTrueFalseTotal
&is_one_of_us($args[0]) and die $args[0] 1 27 28
69 27 die $self->new( @args );
70 }
71  
72 4 ▶sub throw_on_error {
Subroutine throw_on_error: called CC=2 SCAR=6.9
Pod documented
73 4 ▶ my $e; $e = shift->caught( @_ ) and die $e; return;
Branch: 1 branch
BranchTrueFalseTotal
$e = (shift())->caught(@_) and die $e 3 1 4
74 }
75  
76 4 1;
77  
78 __END__
« Unexpected/TraitFor/ErrorLeader.pm ↑ Summary Unexpected/Types.pm »