line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
104
|
|
2096
|
use 5.010001; |
|
104
|
|
|
|
|
400
|
|
19
|
104
|
|
|
104
|
|
660
|
use warnings; |
|
104
|
|
|
|
|
246
|
|
|
104
|
|
|
|
|
2911
|
|
20
|
104
|
|
|
104
|
|
571
|
use strict; |
|
104
|
|
|
|
|
205
|
|
|
104
|
|
|
|
|
2750
|
|
21
|
104
|
|
|
104
|
|
565
|
use English qw( -no_match_vars ); |
|
104
|
|
|
|
|
224
|
|
|
104
|
|
|
|
|
640
|
|
22
|
|
|
|
|
|
|
|
23
|
104
|
|
|
104
|
|
37316
|
use vars qw($VERSION $STRING_VERSION); |
|
104
|
|
|
|
|
235
|
|
|
104
|
|
|
|
|
8919
|
|
24
|
|
|
|
|
|
|
$VERSION = '4.001_053'; |
25
|
|
|
|
|
|
|
$STRING_VERSION = $VERSION; |
26
|
|
|
|
|
|
|
## no critic(BuiltinFunctions::ProhibitStringyEval) |
27
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
28
|
|
|
|
|
|
|
## use critic |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
package Marpa::R3::Internal::X; |
31
|
|
|
|
|
|
|
|
32
|
104
|
|
|
104
|
|
775
|
use warnings; |
|
104
|
|
|
|
|
244
|
|
|
104
|
|
|
|
|
3515
|
|
33
|
104
|
|
|
104
|
|
647
|
use strict; |
|
104
|
|
|
|
|
237
|
|
|
104
|
|
|
|
|
2940
|
|
34
|
104
|
|
|
104
|
|
609
|
use English qw( -no_match_vars ); |
|
104
|
|
|
|
|
284
|
|
|
104
|
|
|
|
|
675
|
|
35
|
104
|
|
|
104
|
|
36341
|
use Scalar::Util qw( blessed ); |
|
104
|
|
|
|
|
257
|
|
|
104
|
|
|
|
|
7337
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use overload |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# an exception is always true |
40
|
104
|
|
|
104
|
|
119795
|
bool => sub {1}, '""' => 'as_string', fallback => 1; |
|
104
|
|
|
0
|
|
98938
|
|
|
104
|
|
|
|
|
916
|
|
|
0
|
|
|
|
|
0
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Create accessor routines |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub throw { |
45
|
3
|
|
|
3
|
|
7
|
my $proto = shift; |
46
|
3
|
50
|
|
|
|
17
|
$proto->rethrow if ref $proto; |
47
|
0
|
|
|
|
|
0
|
die $proto->new(@_); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub rethrow { |
51
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
52
|
3
|
|
|
|
|
25
|
die $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new { |
56
|
3
|
|
|
3
|
|
9
|
my ($class, $args) = @_; |
57
|
3
|
|
50
|
|
|
10
|
$args //= { error => $_[0] }; |
58
|
3
|
|
|
|
|
13
|
return bless $args, $class; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub description { |
62
|
0
|
|
|
0
|
|
0
|
return 'Generic exception'; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub as_string { |
66
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
67
|
3
|
|
|
|
|
6
|
my $string = q{}; |
68
|
3
|
|
|
|
|
8
|
my $to_string = $self->{to_string}; |
69
|
3
|
50
|
33
|
|
|
18
|
if ( $to_string and ref $to_string eq 'CODE' ) { |
70
|
3
|
|
|
|
|
6
|
$string = &{$to_string}($self); |
|
3
|
|
|
|
|
17
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
0
|
|
|
|
|
0
|
FIELD: for my $field ( sort keys %{$self} ) { |
|
0
|
|
|
|
|
0
|
|
74
|
0
|
0
|
|
|
|
0
|
if ( $field eq 'try' ) { |
75
|
0
|
|
|
|
|
0
|
my $try_to_string = $self->{try}; |
76
|
0
|
0
|
|
|
|
0
|
if ( ref $try_to_string ne 'CODE' ) { |
77
|
0
|
|
|
|
|
0
|
$string .= qq{$field: [!not a CODE object!]\n}; |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
0
|
$string .= &{$try_to_string}($self); |
|
0
|
|
|
|
|
0
|
|
80
|
0
|
|
|
|
|
0
|
next FIELD; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
0
|
|
|
|
0
|
next FIELD if $field =~ /\A (slg|slr|tracer|msg|fatal) \z/; |
83
|
0
|
|
|
|
|
0
|
my $value = $self->{$field}; |
84
|
0
|
0
|
|
|
|
0
|
if ( not defined $value ) { |
85
|
0
|
|
|
|
|
0
|
$string .= "$field: [not defined]\n"; |
86
|
0
|
|
|
|
|
0
|
next FIELD; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
0
|
my $ref_type = ref $value; |
89
|
0
|
0
|
|
|
|
0
|
if ($ref_type) { |
90
|
0
|
|
|
|
|
0
|
$string .= "$field: ref to $ref_type\n"; |
91
|
0
|
|
|
|
|
0
|
next FIELD; |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
0
|
$string .= "$field: $value\n"; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
3
|
|
50
|
|
|
17
|
my $fatal = $self->{fatal} // 1; |
97
|
3
|
50
|
|
|
|
10
|
if ($fatal) { |
98
|
3
|
|
|
|
|
8
|
$string = |
99
|
|
|
|
|
|
|
qq{========= Marpa::R3 Fatal error =========\n} |
100
|
|
|
|
|
|
|
. $string |
101
|
|
|
|
|
|
|
. qq{=========================================\n}; |
102
|
|
|
|
|
|
|
} |
103
|
3
|
|
|
|
|
14
|
return $string; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub caught { |
107
|
0
|
|
|
0
|
|
|
my $class = shift; |
108
|
0
|
|
|
|
|
|
my $e = $@; |
109
|
0
|
0
|
0
|
|
|
|
return unless defined $e && blessed($e) && $e->isa($class); |
|
|
|
0
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $e; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |