| 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_054'; | |||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | 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 | 3 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | ▶ | $proto->rethrow if ref $proto; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | die $proto->new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | ▶ | sub rethrow { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rethrow: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | die $self; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | my ($class, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | ▶ | $args //= { error => $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args //= {"error", $_[0]}
MC/DC0%0/1
$args //= {"error", $_[0]}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | return bless $args, $class; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub description { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return 'Generic exception'; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | sub as_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=11 SCAR=39.9
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$to_string and ref $to_string eq "CODE"
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"
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $try_to_string = $self->{try}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ( ref $try_to_string ne 'CODE' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $value = $self->{$field}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( not defined $value ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$self->{"fatal"} // 1
$self->{"fatal"}
Truth table50%1/2
A
A= $self->{"fatal"}
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 3 | ▶ | if ($fatal) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | $string = | |||||||||||||||||||||||||||||||||||||||||
| 99 | qq{========= Marpa::R3 Fatal error =========\n} | ||||||||||||||||||||||||||||||||||||||||||
| 100 | . $string | ||||||||||||||||||||||||||||||||||||||||||
| 101 | . qq{=========================================\n}; | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | return $string; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub caught { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
caught: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $e = $@; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return unless defined $e && blessed($e) && $e->isa($class); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $e and builtin::blessed($e) and $e->isa($class)
defined $e and builtin::blessed($e)
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)
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return $e; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 104 | 1; | |||||||||||||||||||||||||||||||||||||||||