line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
19
|
|
|
19
|
|
225
|
use 5.10.1; |
|
19
|
|
|
|
|
48
|
|
2
|
19
|
|
|
19
|
|
77
|
use strict; |
|
19
|
|
|
|
|
26
|
|
|
19
|
|
|
|
|
371
|
|
3
|
19
|
|
|
19
|
|
77
|
use warnings; |
|
19
|
|
|
|
|
31
|
|
|
19
|
|
|
|
|
773
|
|
4
|
|
|
|
|
|
|
package Data::Processor::Error::Collection; |
5
|
19
|
|
|
19
|
|
116
|
use Carp; |
|
19
|
|
|
|
|
47
|
|
|
19
|
|
|
|
|
930
|
|
6
|
19
|
|
|
19
|
|
5926
|
use Data::Processor::Error::Instance; |
|
19
|
|
|
|
|
41
|
|
|
19
|
|
|
|
|
675
|
|
7
|
|
|
|
|
|
|
|
8
|
19
|
|
|
19
|
|
105
|
use overload ('""' => \&to_string); |
|
19
|
|
|
|
|
28
|
|
|
19
|
|
|
|
|
79
|
|
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
|
350
|
|
|
350
|
1
|
429
|
my $class = shift; |
21
|
350
|
|
|
|
|
670
|
my $self = { |
22
|
|
|
|
|
|
|
errors => [] # the error instances are going into here |
23
|
|
|
|
|
|
|
}; |
24
|
350
|
|
|
|
|
474
|
bless ($self, $class); |
25
|
350
|
|
|
|
|
1232
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 add |
29
|
|
|
|
|
|
|
Adds an error. |
30
|
|
|
|
|
|
|
parameters: |
31
|
|
|
|
|
|
|
- message |
32
|
|
|
|
|
|
|
- path |
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
sub add { |
35
|
40
|
|
|
40
|
1
|
52
|
my $self = shift; |
36
|
40
|
|
|
|
|
111
|
my %p = @_; |
37
|
40
|
|
|
|
|
181
|
my $error = Data::Processor::Error::Instance->new(%p); |
38
|
40
|
|
|
|
|
50
|
push @{$self->{errors}}, $error; |
|
40
|
|
|
|
|
124
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 add_error |
42
|
|
|
|
|
|
|
Adds an error object |
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
sub add_error { |
45
|
13
|
|
|
13
|
1
|
14
|
my $self = shift; |
46
|
13
|
|
|
|
|
15
|
my $e = shift; |
47
|
13
|
|
|
|
|
13
|
push @{$self->{errors}}, $e; |
|
13
|
|
|
|
|
43
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 add_collection |
51
|
|
|
|
|
|
|
Adds another error collection |
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
sub add_collection{ |
54
|
105
|
|
|
105
|
1
|
144
|
my $self = shift; |
55
|
105
|
|
|
|
|
102
|
my $other = shift; |
56
|
105
|
|
|
|
|
198
|
my @e = $other->as_array(); |
57
|
105
|
|
|
|
|
311
|
for (@e){ |
58
|
13
|
|
|
|
|
35
|
$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
|
18
|
my $self = shift; |
72
|
8
|
|
|
|
|
23
|
my %p = @_; |
73
|
8
|
|
|
|
|
19
|
for ('string', 'field'){ |
74
|
|
|
|
|
|
|
croak "cannot check for errors without '$_'" |
75
|
16
|
50
|
|
|
|
34
|
unless $p{$_}; |
76
|
|
|
|
|
|
|
} |
77
|
8
|
|
|
|
|
10
|
for my $error (@{$self->{errors}}){ |
|
8
|
|
|
|
|
17
|
|
78
|
20
|
100
|
|
|
|
247
|
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
|
338
|
|
|
338
|
1
|
358
|
my $self = shift; |
87
|
338
|
|
|
|
|
321
|
return @{$self->{errors}}; |
|
338
|
|
|
|
|
1754
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 count |
91
|
|
|
|
|
|
|
Return count of errors. |
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
sub count { |
94
|
80
|
|
|
80
|
1
|
517
|
my $self = shift; |
95
|
80
|
|
|
|
|
80
|
return scalar @{$self->{errors}}; |
|
80
|
|
|
|
|
670
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub to_string { |
99
|
221
|
|
|
221
|
0
|
512
|
my $self = shift; |
100
|
221
|
|
|
|
|
366
|
return join "\n", $self->as_array; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|