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