line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Error::Pure::Output::Text; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
8
|
|
|
8
|
|
50367
|
use base qw(Exporter); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
873
|
|
5
|
8
|
|
|
8
|
|
39
|
use strict; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
163
|
|
6
|
8
|
|
|
8
|
|
36
|
use warnings; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
241
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# Modules. |
9
|
8
|
|
|
8
|
|
6984
|
use Readonly; |
|
8
|
|
|
|
|
25543
|
|
|
8
|
|
|
|
|
10041
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Constants. |
12
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(err_bt_pretty err_bt_pretty_rev err_line |
13
|
|
|
|
|
|
|
err_line_all err_print err_print_var); |
14
|
|
|
|
|
|
|
Readonly::Scalar our $EMPTY_STR => q{}; |
15
|
|
|
|
|
|
|
Readonly::Scalar our $SPACE => q{ }; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Version. |
18
|
|
|
|
|
|
|
our $VERSION = 0.22; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Pretty print of backtrace. |
21
|
|
|
|
|
|
|
sub err_bt_pretty { |
22
|
6
|
|
|
6
|
1
|
1955
|
my @errors = @_; |
23
|
6
|
|
|
|
|
8
|
my @ret; |
24
|
6
|
|
|
|
|
14
|
my $l_ar = _lenghts(@errors); |
25
|
6
|
|
|
|
|
10
|
foreach my $error_hr (@errors) { |
26
|
7
|
|
|
|
|
14
|
push @ret, _bt_pretty_one($error_hr, $l_ar); |
27
|
|
|
|
|
|
|
} |
28
|
6
|
100
|
|
|
|
51
|
return wantarray ? @ret : (join "\n", @ret)."\n"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Reverse pretty print of backtrace. |
32
|
|
|
|
|
|
|
sub err_bt_pretty_rev { |
33
|
5
|
|
|
5
|
1
|
2465
|
my @errors = @_; |
34
|
5
|
|
|
|
|
8
|
my @ret; |
35
|
5
|
|
|
|
|
12
|
my $l_ar = _lenghts(@errors); |
36
|
5
|
|
|
|
|
7
|
foreach my $error_hr (reverse @errors) { |
37
|
6
|
|
|
|
|
14
|
push @ret, _bt_pretty_one($error_hr, $l_ar); |
38
|
|
|
|
|
|
|
} |
39
|
5
|
100
|
|
|
|
47
|
return wantarray ? @ret : (join "\n", @ret)."\n"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Pretty print line error. |
43
|
|
|
|
|
|
|
sub err_line { |
44
|
3
|
|
|
3
|
1
|
1314
|
my @errors = @_; |
45
|
3
|
|
|
|
|
10
|
return _err_line($errors[-1]); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Pretty print with errors each on one line. |
49
|
|
|
|
|
|
|
sub err_line_all { |
50
|
3
|
|
|
3
|
1
|
1434
|
my @errors = @_; |
51
|
3
|
|
|
|
|
5
|
my $ret; |
52
|
3
|
|
|
|
|
7
|
foreach my $error_hr (@errors) { |
53
|
4
|
|
|
|
|
11
|
$ret .= _err_line($error_hr); |
54
|
|
|
|
|
|
|
} |
55
|
3
|
|
|
|
|
9
|
return $ret; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Print error. |
59
|
|
|
|
|
|
|
sub err_print { |
60
|
6
|
|
|
6
|
1
|
5527
|
my @errors = @_; |
61
|
6
|
|
|
|
|
29
|
my $class = _err_class($errors[-1]); |
62
|
6
|
|
|
|
|
39
|
return $class.$errors[-1]->{'msg'}->[0]; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Print error with all variables. |
66
|
|
|
|
|
|
|
sub err_print_var { |
67
|
7
|
|
|
7
|
1
|
3358
|
my @errors = @_; |
68
|
7
|
|
|
|
|
10
|
my @msg = @{$errors[-1]->{'msg'}}; |
|
7
|
|
|
|
|
19
|
|
69
|
7
|
|
|
|
|
17
|
my $class = _err_class($errors[-1]); |
70
|
7
|
|
|
|
|
17
|
my @ret = ($class.(shift @msg)); |
71
|
7
|
|
|
|
|
14
|
push @ret, _err_variables(@msg); |
72
|
7
|
100
|
|
|
|
35
|
return wantarray ? @ret : (join "\n", @ret)."\n"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Pretty print one error backtrace helper. |
76
|
|
|
|
|
|
|
sub _bt_pretty_one { |
77
|
13
|
|
|
13
|
|
17
|
my ($error_hr, $l_ar) = @_; |
78
|
13
|
|
|
|
|
44
|
my @msg = @{$error_hr->{'msg'}}; |
|
13
|
|
|
|
|
31
|
|
79
|
13
|
|
|
|
|
31
|
my @ret = ('ERROR: '.(shift @msg)); |
80
|
13
|
|
|
|
|
28
|
push @ret, _err_variables(@msg); |
81
|
13
|
|
|
|
|
18
|
foreach my $i (0 .. $#{$error_hr->{'stack'}}) { |
|
13
|
|
|
|
|
31
|
|
82
|
19
|
|
|
|
|
27
|
my $st = $error_hr->{'stack'}->[$i]; |
83
|
19
|
|
|
|
|
28
|
my $ret = $st->{'class'}; |
84
|
19
|
|
|
|
|
49
|
$ret .= $SPACE x ($l_ar->[0] - length $st->{'class'}); |
85
|
19
|
|
|
|
|
24
|
$ret .= $st->{'sub'}; |
86
|
19
|
|
|
|
|
33
|
$ret .= $SPACE x ($l_ar->[1] - length $st->{'sub'}); |
87
|
19
|
|
|
|
|
25
|
$ret .= $st->{'prog'}; |
88
|
19
|
|
|
|
|
30
|
$ret .= $SPACE x ($l_ar->[2] - length $st->{'prog'}); |
89
|
19
|
|
|
|
|
22
|
$ret .= $st->{'line'}; |
90
|
19
|
|
|
|
|
53
|
push @ret, $ret; |
91
|
|
|
|
|
|
|
} |
92
|
13
|
|
|
|
|
44
|
return @ret; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Print class if class isn't main. |
96
|
|
|
|
|
|
|
sub _err_class { |
97
|
13
|
|
|
13
|
|
23
|
my $error_hr = shift; |
98
|
13
|
|
|
|
|
32
|
my $class = $error_hr->{'stack'}->[0]->{'class'}; |
99
|
13
|
100
|
|
|
|
53
|
if ($class eq 'main') { |
100
|
11
|
|
|
|
|
26
|
$class = $EMPTY_STR; |
101
|
|
|
|
|
|
|
} |
102
|
13
|
100
|
|
|
|
33
|
if ($class) { |
103
|
2
|
|
|
|
|
8
|
$class .= ': '; |
104
|
|
|
|
|
|
|
} |
105
|
13
|
|
|
|
|
32
|
return $class; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Pretty print line error. |
109
|
|
|
|
|
|
|
sub _err_line { |
110
|
7
|
|
|
7
|
|
9
|
my $error_hr = shift; |
111
|
7
|
|
|
|
|
14
|
my $stack_ar = $error_hr->{'stack'}; |
112
|
7
|
|
|
|
|
10
|
my $msg = $error_hr->{'msg'}; |
113
|
7
|
|
|
|
|
10
|
my $prog = $stack_ar->[0]->{'prog'}; |
114
|
7
|
|
|
|
|
29
|
$prog =~ s/^\.\///gms; |
115
|
7
|
|
|
|
|
13
|
my $e = $msg->[0]; |
116
|
7
|
|
|
|
|
14
|
chomp $e; |
117
|
7
|
|
|
|
|
33
|
return "#Error [$prog:$stack_ar->[0]->{'line'}] $e\n"; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# Process variables. |
121
|
|
|
|
|
|
|
sub _err_variables { |
122
|
20
|
|
|
20
|
|
51
|
my @msg = @_; |
123
|
20
|
|
|
|
|
22
|
my @ret; |
124
|
20
|
|
|
|
|
53
|
while (@msg) { |
125
|
14
|
|
|
|
|
22
|
my $f = shift @msg; |
126
|
14
|
|
|
|
|
18
|
my $t = shift @msg; |
127
|
|
|
|
|
|
|
|
128
|
14
|
100
|
|
|
|
33
|
if (! defined $f) { |
129
|
2
|
|
|
|
|
3
|
last; |
130
|
|
|
|
|
|
|
} |
131
|
12
|
|
|
|
|
14
|
my $ret = $f; |
132
|
12
|
100
|
|
|
|
28
|
if (defined $t) { |
133
|
9
|
|
|
|
|
16
|
chomp $t; |
134
|
9
|
|
|
|
|
14
|
$ret .= ': '.$t; |
135
|
|
|
|
|
|
|
} |
136
|
12
|
|
|
|
|
29
|
push @ret, $ret; |
137
|
|
|
|
|
|
|
} |
138
|
20
|
|
|
|
|
37
|
return @ret; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Gets length for errors. |
142
|
|
|
|
|
|
|
sub _lenghts { |
143
|
11
|
|
|
11
|
|
17
|
my @errors = @_; |
144
|
11
|
|
|
|
|
20
|
my $l_ar = [0, 0, 0]; |
145
|
11
|
|
|
|
|
21
|
foreach my $error_hr (@errors) { |
146
|
13
|
|
|
|
|
14
|
foreach my $st (@{$error_hr->{'stack'}}) { |
|
13
|
|
|
|
|
25
|
|
147
|
19
|
100
|
|
|
|
47
|
if (length $st->{'class'} > $l_ar->[0]) { |
148
|
11
|
|
|
|
|
17
|
$l_ar->[0] = length $st->{'class'}; |
149
|
|
|
|
|
|
|
} |
150
|
19
|
100
|
|
|
|
43
|
if (length $st->{'sub'} > $l_ar->[1]) { |
151
|
15
|
|
|
|
|
21
|
$l_ar->[1] = length $st->{'sub'}; |
152
|
|
|
|
|
|
|
} |
153
|
19
|
100
|
|
|
|
46
|
if (length $st->{'prog'} > $l_ar->[2]) { |
154
|
11
|
|
|
|
|
25
|
$l_ar->[2] = length $st->{'prog'}; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
11
|
|
|
|
|
17
|
$l_ar->[0] += 2; |
159
|
11
|
|
|
|
|
15
|
$l_ar->[1] += 2; |
160
|
11
|
|
|
|
|
13
|
$l_ar->[2] += 2; |
161
|
11
|
|
|
|
|
20
|
return $l_ar; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |