line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Transpose::Validator::Group; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
56
|
use strict; |
|
11
|
|
|
|
|
16
|
|
|
11
|
|
|
|
|
388
|
|
4
|
11
|
|
|
11
|
|
51
|
use warnings; |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
323
|
|
5
|
|
|
|
|
|
|
|
6
|
11
|
|
|
11
|
|
46
|
use Moo; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
69
|
|
7
|
|
|
|
|
|
|
extends 'Data::Transpose::Validator::Base'; |
8
|
11
|
|
|
11
|
|
3342
|
use MooX::Types::MooseLike::Base qw(:all); |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
4787
|
|
9
|
11
|
|
|
11
|
|
67
|
use namespace::clean; |
|
11
|
|
|
|
|
34
|
|
|
11
|
|
|
|
|
84
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Data::Transpose::Validator::Group - Class for grouped field |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHODS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 new(name => "name", fields => [$obj1, $obj2, ... ]) |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has fields => (is => 'ro', |
24
|
|
|
|
|
|
|
isa => ArrayRef); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has name => (is => 'ro', |
27
|
|
|
|
|
|
|
isa => Str); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has equal => (is => 'rw', |
30
|
|
|
|
|
|
|
isa => Bool, |
31
|
|
|
|
|
|
|
default => sub { 1 }); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 fields |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Return an arrayref of the objects set in the constructor. This is read only. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 name |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Return the name set in the constructor. This is read only. If you want |
41
|
|
|
|
|
|
|
a sensible default error string, you should set this to something that |
42
|
|
|
|
|
|
|
concatenated with "%s differ" makes sense. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
E.g. "passwords" will produce such an error: "Passwords differ!"; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 equal |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Set to a true value if the check for equality is needed. Defaults to |
49
|
|
|
|
|
|
|
true, and so far it's the only use of this module. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 is_valid |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Returns true if the group validates. If no check were done (because, |
54
|
|
|
|
|
|
|
e.g. you set equal => 0) this method returns true but sets a warning, |
55
|
|
|
|
|
|
|
which you can retrieve with -C. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub is_valid { |
61
|
14
|
|
|
14
|
1
|
21
|
my $self = shift; |
62
|
14
|
|
|
|
|
67
|
$self->reset_errors; |
63
|
14
|
|
|
|
|
592
|
$self->reset_warnings; |
64
|
14
|
|
|
|
|
2076
|
my $valid = 1; |
65
|
14
|
|
|
|
|
20
|
my $checks = 0; |
66
|
14
|
100
|
|
|
|
273
|
if ($self->equal) { |
67
|
11
|
|
|
|
|
617
|
$valid = $self->_check_if_fields_are_equal; |
68
|
11
|
|
|
|
|
22
|
$checks++; |
69
|
|
|
|
|
|
|
} |
70
|
14
|
100
|
100
|
|
|
100
|
if ($valid && !$checks) { |
71
|
|
|
|
|
|
|
# unclear if we should die here or just warn. But the user |
72
|
|
|
|
|
|
|
# could very well not check the warnings. |
73
|
3
|
|
|
|
|
23
|
$self->warnings("No check were done"); |
74
|
|
|
|
|
|
|
} |
75
|
14
|
|
|
|
|
70
|
return $valid; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _check_if_fields_are_equal { |
80
|
11
|
|
|
11
|
|
19
|
my $self = shift; |
81
|
11
|
|
|
|
|
14
|
my @fields = @{$self->fields}; |
|
11
|
|
|
|
|
49
|
|
82
|
11
|
|
|
|
|
14
|
my $value; |
83
|
11
|
|
|
|
|
15
|
my $equal = 1; |
84
|
11
|
|
|
|
|
22
|
foreach my $f (@fields) { |
85
|
|
|
|
|
|
|
# first run the value is undef, so we can't check |
86
|
22
|
100
|
|
|
|
39
|
if (defined $value) { |
87
|
11
|
100
|
|
|
|
225
|
if ($value ne $f->dtv_value) { |
88
|
6
|
|
|
|
|
15
|
$equal = 0; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
else { |
92
|
11
|
|
|
|
|
237
|
$value = $f->dtv_value; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
11
|
100
|
|
|
|
34
|
unless ($equal) { |
96
|
6
|
|
|
|
|
39
|
my $name = ucfirst($self->name); |
97
|
6
|
|
|
|
|
65
|
$self->error([ not_equal => "$name differ!" ]); |
98
|
|
|
|
|
|
|
} |
99
|
11
|
|
|
|
|
24
|
return $equal; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |