line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Verifier::Field; |
2
|
|
|
|
|
|
|
$Data::Verifier::Field::VERSION = '0.61'; |
3
|
17
|
|
|
17
|
|
66
|
use Moose; |
|
17
|
|
|
|
|
21
|
|
|
17
|
|
|
|
|
74
|
|
4
|
17
|
|
|
17
|
|
73692
|
use MooseX::Storage; |
|
17
|
|
|
|
|
451905
|
|
|
17
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'MooseX::Storage::Deferred'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Field from a Data::Verifier profile |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has original_value => ( |
12
|
|
|
|
|
|
|
is => 'rw', |
13
|
|
|
|
|
|
|
isa => 'Maybe[Str|ArrayRef|HashRef]', |
14
|
|
|
|
|
|
|
predicate => 'has_original_value' |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has post_filter_value => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
isa => 'Maybe[Str|ArrayRef|HashRef]', |
21
|
|
|
|
|
|
|
predicate => 'has_post_filter_value' |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has reason => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
isa => 'Str', |
28
|
|
|
|
|
|
|
predicate => 'has_reason' |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has valid => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
isa => 'Bool', |
35
|
|
|
|
|
|
|
default => 1 |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has value => ( |
40
|
|
|
|
|
|
|
traits => [ 'DoNotSerialize' ], |
41
|
|
|
|
|
|
|
is => 'rw', |
42
|
|
|
|
|
|
|
isa => 'Any', |
43
|
|
|
|
|
|
|
clearer => 'clear_value' |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=pod |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Data::Verifier::Field - Field from a Data::Verifier profile |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 VERSION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
version 0.61 |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use Data::Verifier; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $dv = Data::Verifier->new(profile => { |
67
|
|
|
|
|
|
|
name => { |
68
|
|
|
|
|
|
|
required => 1, |
69
|
|
|
|
|
|
|
type => 'Str', |
70
|
|
|
|
|
|
|
filters => [ qw(collapse trim) ] |
71
|
|
|
|
|
|
|
}, |
72
|
|
|
|
|
|
|
age => { |
73
|
|
|
|
|
|
|
type => 'Int' |
74
|
|
|
|
|
|
|
}, |
75
|
|
|
|
|
|
|
sign => { |
76
|
|
|
|
|
|
|
required => 1, |
77
|
|
|
|
|
|
|
type => 'Str' |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
}); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $results = $dv->verify({ |
82
|
|
|
|
|
|
|
name => 'Cory', age => 'foobar' |
83
|
|
|
|
|
|
|
}); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $field = $results->get_field('name'); |
87
|
|
|
|
|
|
|
print $field->value; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Data::Verifier::Field provides all post-verification information on a given |
92
|
|
|
|
|
|
|
field. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 original_value |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The string value of the field before any filters or coercion. This will |
99
|
|
|
|
|
|
|
survive serialization whereas value will not. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 post_filter_value |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The string value of the field before after filters but before coercion. This |
104
|
|
|
|
|
|
|
will survive serialization whereas value will not. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 reason |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
If this field is invalid then this attribute should contain a "reason". Out |
109
|
|
|
|
|
|
|
of the box it will always contain a string. One of: |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=over 4 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item B<dependent> |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
A dependent check failed. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item B<has_coerced_value> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Predicate for the C<coerced_value> attribute. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item B<max_length> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The value was larger than the field's max length. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item B<min_length> |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
The value was shorter than the field's min length. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item B<post_check> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The post check failed. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item B<type_constraint> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
The value did not pass the type constraint. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item B<derived> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The value failed because a value derived from it failed. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=back |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 valid |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Boolean value representing this fields validity. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 value |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
The value of this field. This will not be present if serialized, as it could |
150
|
|
|
|
|
|
|
be any value, some of which we may not know how to Serialize. See |
151
|
|
|
|
|
|
|
C<original_value>. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 METHODS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 has_original_value |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Predicate that returns true if this field has an original value. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 has_post_filter_value |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Predicate that returns true if this field has a post filter value. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 has_reason |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Predicate that returns true if this field has a reason. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 clear_value |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Clears the value attribute. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 AUTHOR |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Cory G Watson <gphat@cpan.org> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Cold Hard Code, LLC. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
180
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |