line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
19
|
|
|
19
|
|
272
|
use 5.10.1; |
|
19
|
|
|
|
|
59
|
|
2
|
19
|
|
|
19
|
|
100
|
use strict; |
|
19
|
|
|
|
|
28
|
|
|
19
|
|
|
|
|
487
|
|
3
|
19
|
|
|
19
|
|
102
|
use warnings; |
|
19
|
|
|
|
|
42
|
|
|
19
|
|
|
|
|
910
|
|
4
|
|
|
|
|
|
|
package Data::Processor::Error::Collection; |
5
|
19
|
|
|
19
|
|
132
|
use Carp; |
|
19
|
|
|
|
|
61
|
|
|
19
|
|
|
|
|
1134
|
|
6
|
19
|
|
|
19
|
|
7074
|
use Data::Processor::Error::Instance; |
|
19
|
|
|
|
|
48
|
|
|
19
|
|
|
|
|
786
|
|
7
|
|
|
|
|
|
|
|
8
|
19
|
|
|
19
|
|
125
|
use overload ('""' => \&to_string); |
|
19
|
|
|
|
|
37
|
|
|
19
|
|
|
|
|
88
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
Data::Processor::Error::Collection - Collect errors for Data::Processor |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 METHODS |
14
|
|
|
|
|
|
|
=head2 new |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $errors = Data::Processor::Error::Collection->new(); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
sub new { |
20
|
319
|
|
|
319
|
1
|
515
|
my $class = shift; |
21
|
319
|
|
|
|
|
714
|
my $self = { |
22
|
|
|
|
|
|
|
errors => [] # the error instances are going into here |
23
|
|
|
|
|
|
|
}; |
24
|
319
|
|
|
|
|
510
|
bless ($self, $class); |
25
|
319
|
|
|
|
|
1430
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 add |
29
|
|
|
|
|
|
|
Adds an error. |
30
|
|
|
|
|
|
|
parameters: |
31
|
|
|
|
|
|
|
- message |
32
|
|
|
|
|
|
|
- path |
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
sub add { |
35
|
39
|
|
|
39
|
1
|
65
|
my $self = shift; |
36
|
39
|
|
|
|
|
141
|
my %p = @_; |
37
|
39
|
|
|
|
|
224
|
my $error = Data::Processor::Error::Instance->new(%p); |
38
|
39
|
|
|
|
|
90
|
push @{$self->{errors}}, $error; |
|
39
|
|
|
|
|
157
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 add_error |
42
|
|
|
|
|
|
|
Adds an error object |
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
sub add_error { |
45
|
12
|
|
|
12
|
1
|
18
|
my $self = shift; |
46
|
12
|
|
|
|
|
26
|
my $e = shift; |
47
|
12
|
|
|
|
|
16
|
push @{$self->{errors}}, $e; |
|
12
|
|
|
|
|
45
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 add_collection |
51
|
|
|
|
|
|
|
Adds another error collection |
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
sub add_collection{ |
54
|
96
|
|
|
96
|
1
|
152
|
my $self = shift; |
55
|
96
|
|
|
|
|
122
|
my $other = shift; |
56
|
96
|
|
|
|
|
186
|
my @e = $other->as_array(); |
57
|
96
|
|
|
|
|
326
|
for (@e){ |
58
|
12
|
|
|
|
|
26
|
$self->add_error($_); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 any_error_contains |
64
|
|
|
|
|
|
|
Return true if any of the collected errors contains a given string. |
65
|
|
|
|
|
|
|
$error->collection->any_error_contains( |
66
|
|
|
|
|
|
|
string => "error_msg", |
67
|
|
|
|
|
|
|
field => "message", # any of the data fields of an error |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
sub any_error_contains { |
71
|
8
|
|
|
8
|
1
|
17
|
my $self = shift; |
72
|
8
|
|
|
|
|
30
|
my %p = @_; |
73
|
8
|
|
|
|
|
21
|
for ('string', 'field'){ |
74
|
|
|
|
|
|
|
croak "cannot check for errors without '$_'" |
75
|
16
|
50
|
|
|
|
53
|
unless $p{$_}; |
76
|
|
|
|
|
|
|
} |
77
|
8
|
|
|
|
|
14
|
for my $error (@{$self->{errors}}){ |
|
8
|
|
|
|
|
20
|
|
78
|
23
|
100
|
|
|
|
298
|
return 1 if $error->{$p{field}} =~ /$p{string}/; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 as_array |
83
|
|
|
|
|
|
|
Return all collected errors as an array. |
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
sub as_array { |
86
|
308
|
|
|
308
|
1
|
414
|
my $self = shift; |
87
|
308
|
|
|
|
|
357
|
return @{$self->{errors}}; |
|
308
|
|
|
|
|
2048
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 count |
91
|
|
|
|
|
|
|
Return count of errors. |
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
sub count { |
94
|
71
|
|
|
71
|
1
|
658
|
my $self = shift; |
95
|
71
|
|
|
|
|
110
|
return scalar @{$self->{errors}}; |
|
71
|
|
|
|
|
356
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub to_string { |
99
|
200
|
|
|
200
|
0
|
583
|
my $self = shift; |
100
|
200
|
|
|
|
|
391
|
return join "\n", $self->as_array; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|