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