R3/X.pm

filter: Statementstmt 65.7% 50 / 76 Branchbran 16.6% 3 / 18 Conditioncond 23.0% 3 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 82.3% 14 / 17 Podpod n/a totaltotal 53.4% 70 / 131 CC 16 SCAR 30.8
CC
16
Cov
52%
as_string
54.0
caught
20.0
throw
2.3
CRAP 21.8
« R3/MetaAST.pm ↑ Summary R3/Common.pm »
1 # Marpa::R3 is Copyright (C) 2018, Jeffrey Kegler.
2 #
3 # This module is free software; you can redistribute it and/or modify it
4 # under the same terms as Perl 5.10.1. For more details, see the full text
5 # of the licenses in the directory LICENSES.
6 #
7 # This program is distributed in the hope that it will be
8 # useful, but it is provided "as is" and without any express
9 # or implied warranties. For details, see the full text of
10 # of the licenses in the directory LICENSES.
11  
12 # Marpa::R3 exceptions and their methods
13  
14 # Adapted from CPAN's Exception::Class module
15  
16 package Marpa::R3::X;
17  
18 104 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 104 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 104 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 104 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 104 ▶use vars qw($VERSION $STRING_VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 104 $VERSION = '4.001_053';
25 104 $STRING_VERSION = $VERSION;
26 ## no critic(BuiltinFunctions::ProhibitStringyEval)
27 104 $VERSION = eval $VERSION;
28 ## use critic
29  
30 package Marpa::R3::Internal::X;
31  
32 104 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 104 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 104 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
35 104 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 use overload
38  
39 # an exception is always true
40 104 ▶ bool => sub {1}, '""' => 'as_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
41  
42 # Create accessor routines
43  
44 sub throw {
45 3 ▶ my $proto = shift;
Subroutine throw: called CC=2 SCAR=8.1
46 3 ▶ $proto->rethrow if ref $proto;
Branch: 1 branch
BranchTrueFalseTotal
if ref $proto 3 0 3
47 0 die $proto->new(@_);
48 }
49  
50 sub rethrow {
51 3 ▶ my $self = shift;
Subroutine rethrow: called CC=1 SCAR=0.0
52 3 die $self;
53 }
54  
55 sub new {
56 3 ▶ my ($class, $args) = @_;
Subroutine new: called CC=2 SCAR=7.1
57 3 ▶ $args //= { error => $_[0] };
Condition50%1/2
$args //= {"error", $_[0]}
l!l
30
MC/DC0%0/1
$args //= {"error", $_[0]}
$args
Truth table50%1/2
A
A= $args
Aresult
11
00
58 3 return bless $args, $class;
59 }
60  
61 sub description {
62 0 ▶ return 'Generic exception';
Subroutine description: not called CC=1 SCAR=6.9
63 }
64  
65 sub as_string {
66 3 ▶ my $self = shift;
Subroutine as_string: called CC=11 SCAR=39.9
67 3 my $string = q{};
68 3 my $to_string = $self->{to_string};
69 3 ▶ if ( $to_string and ref $to_string eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to_string and ref $to_string eq 'CODE') { } 3 0 3
Condition33%1/3
$to_string and ref $to_string eq "CODE"
!ll&&!rl&&r
003
MC/DC0%0/2
$to_string and ref $to_string eq "CODE"
$to_string ref $to_string eq "CODE"
Truth table33%1/3
A and B
A= $to_stringB= ref $to_string eq "CODE"
ABresult
0X0
100
111
70 3 $string = &{$to_string}($self);
71 }
72 else {
73 0 FIELD: for my $field ( sort keys %{$self} ) {
74 0 ▶ if ( $field eq 'try' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq "try") 0 0 0
75 0 my $try_to_string = $self->{try};
76 0 ▶ if ( ref $try_to_string ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $try_to_string ne "CODE") 0 0 0
77 0 $string .= qq{$field: [!not a CODE object!]\n};
78 }
79 0 $string .= &{$try_to_string}($self);
80 0 next FIELD;
81 }
82 0 ▶ next FIELD if $field =~ /\A (slg|slr|tracer|msg|fatal) \z/;
Branch: 1 branch
BranchTrueFalseTotal
if $field =~ /\A (slg|slr|tracer|msg|fatal) \z/ 0 0 0
83 0 my $value = $self->{$field};
84 0 ▶ if ( not defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
85 0 $string .= "$field: [not defined]\n";
86 0 next FIELD;
87 }
88 0 my $ref_type = ref $value;
89 0 ▶ if ($ref_type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref_type) 0 0 0
90 0 $string .= "$field: ref to $ref_type\n";
91 0 next FIELD;
92 }
93 0 $string .= "$field: $value\n";
94 }
95 }
96 3 ▶ my $fatal = $self->{fatal} // 1;
Condition50%1/2
$self->{"fatal"} // 1
l!l
03
MC/DC0%0/1
$self->{"fatal"} // 1
$self->{"fatal"}
Truth table50%1/2
A
A= $self->{"fatal"}
Aresult
11
00
97 3 ▶ if ($fatal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fatal) 3 0 3
98 3 $string =
99 qq{========= Marpa::R3 Fatal error =========\n}
100 . $string
101 . qq{=========================================\n};
102 }
103 3 return $string;
104 }
105  
106 sub caught {
107 0 ▶ my $class = shift;
Subroutine caught: not called CC=4 SCAR=30.0
108 0 my $e = $@;
109 0 ▶ return unless defined $e && blessed($e) && $e->isa($class);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e and builtin::blessed($e) and $e->isa($class) 0 0 0
Condition0%0/6
defined $e and builtin::blessed($e) and $e->isa($class)
!ll&&!rl&&r
000
defined $e and builtin::blessed($e)
!ll&&!rl&&r
000
MC/DC0%0/3
defined $e and builtin::blessed($e) and $e->isa($class)
defined $e builtin::blessed($e) $e->isa($class)
Truth table0%0/4
A and B and C
A= defined $eB= builtin::blessed($e)C= $e->isa($class)
ABCresult
0XX0
10X0
1100
1111
110 0 return $e;
111 }
112  
113 104 1;
« R3/MetaAST.pm ↑ Summary R3/Common.pm »