line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Syccess::Field; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
9
|
|
|
9
|
|
4445
|
$Syccess::Field::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Syccess field |
6
|
|
|
|
|
|
|
$Syccess::Field::VERSION = '0.103'; |
7
|
9
|
|
|
9
|
|
89
|
use Moo; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
52
|
|
8
|
9
|
|
|
9
|
|
2335
|
use Module::Runtime qw( use_module ); |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
55
|
|
9
|
9
|
|
|
9
|
|
5174
|
use Module::Load::Conditional qw( can_load ); |
|
9
|
|
|
|
|
205495
|
|
|
9
|
|
|
|
|
5767
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with qw( |
12
|
|
|
|
|
|
|
MooX::Traits |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has syccess => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
required => 1, |
18
|
|
|
|
|
|
|
weak_ref => 1, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has name => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
required => 1, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has label => ( |
27
|
|
|
|
|
|
|
is => 'lazy', |
28
|
|
|
|
|
|
|
init_arg => undef, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _build_label { |
32
|
18
|
|
|
18
|
|
2855
|
my ( $self ) = @_; |
33
|
18
|
50
|
|
|
|
87
|
if (ref $self->validators_list eq 'HASH') { |
34
|
0
|
0
|
|
|
|
0
|
return $self->validators_list->{label} |
35
|
|
|
|
|
|
|
if defined $self->validators_list->{label}; |
36
|
|
|
|
|
|
|
} else { |
37
|
18
|
|
|
|
|
18
|
my @validators_list = @{$self->validators_list}; |
|
18
|
|
|
|
|
63
|
|
38
|
18
|
|
|
|
|
55
|
while (@validators_list) { |
39
|
21
|
|
|
|
|
45
|
my ( $key, $arg ) = splice(@validators_list,0,2); |
40
|
21
|
100
|
|
|
|
89
|
return $arg if $key eq 'label'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
15
|
|
|
|
|
103
|
return ucfirst($self->name); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has validators_args => ( |
47
|
|
|
|
|
|
|
is => 'ro', |
48
|
|
|
|
|
|
|
predicate => 1, |
49
|
|
|
|
|
|
|
); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has validators_list => ( |
52
|
|
|
|
|
|
|
is => 'ro', |
53
|
|
|
|
|
|
|
required => 1, |
54
|
|
|
|
|
|
|
init_arg => 'validators', |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has validators => ( |
58
|
|
|
|
|
|
|
is => 'lazy', |
59
|
|
|
|
|
|
|
init_arg => undef, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _build_validators { |
63
|
19
|
|
|
19
|
|
2910
|
my ( $self ) = @_; |
64
|
0
|
|
|
|
|
0
|
my %validators_args = $self->has_validators_args |
65
|
19
|
50
|
|
|
|
95
|
? (%{$self->validators_args}) : (); |
66
|
19
|
|
|
|
|
23
|
my @validators; |
67
|
0
|
|
|
|
|
0
|
my @validators_list = ref $self->validators_list eq 'HASH' |
68
|
0
|
|
|
|
|
0
|
? ( map { $_, $self->validators_list->{$_} } |
69
|
0
|
|
|
|
|
0
|
sort { $a cmp $b } |
70
|
19
|
|
|
|
|
61
|
keys %{$self->validators_list} ) |
71
|
19
|
50
|
|
|
|
84
|
: ( @{$self->validators_list} ); |
72
|
19
|
|
|
|
|
86
|
while (@validators_list) { |
73
|
22
|
|
|
|
|
925
|
my ( $key, $arg ) = splice(@validators_list,0,2); |
74
|
22
|
100
|
|
|
|
64
|
next if $key eq 'label'; |
75
|
19
|
|
|
|
|
21
|
my %args; |
76
|
19
|
100
|
|
|
|
48
|
if (ref $arg eq 'HASH') { |
77
|
10
|
|
|
|
|
13
|
%args = %{$arg}; |
|
10
|
|
|
|
|
37
|
|
78
|
|
|
|
|
|
|
} else { |
79
|
9
|
|
|
|
|
20
|
$args{arg} = $arg; |
80
|
|
|
|
|
|
|
} |
81
|
19
|
|
|
|
|
32
|
$args{syccess_field} = $self; |
82
|
19
|
|
|
|
|
52
|
push @validators, $self->load_class_by_key($key)->new( |
83
|
|
|
|
|
|
|
%validators_args, %args |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
} |
86
|
19
|
|
|
|
|
3456
|
return [ @validators ]; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has load_class_cache => ( |
90
|
|
|
|
|
|
|
is => 'ro', |
91
|
|
|
|
|
|
|
init_arg => undef, |
92
|
|
|
|
|
|
|
default => sub {{}}, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub load_class_by_key { |
96
|
19
|
|
|
19
|
0
|
30
|
my ( $self, $key ) = @_; |
97
|
19
|
50
|
|
|
|
77
|
return $self->load_class_cache->{$key} if defined $self->load_class_cache->{$key}; |
98
|
19
|
|
|
|
|
21
|
my $class; |
99
|
19
|
50
|
|
|
|
53
|
if ($key =~ m/::/) { |
100
|
0
|
0
|
|
|
|
0
|
if (can_load( modules => { $key, 0 } )) { |
101
|
0
|
|
|
|
|
0
|
$class = $key; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} else { |
104
|
19
|
|
|
|
|
27
|
my $module = $key; |
105
|
19
|
|
|
|
|
40
|
$module =~ s/_([a-z])/\U$1/; |
106
|
19
|
|
|
|
|
43
|
$module = ucfirst($module); |
107
|
19
|
|
|
|
|
24
|
my @namespaces = @{$self->syccess->validator_namespaces}; |
|
19
|
|
|
|
|
298
|
|
108
|
19
|
|
|
|
|
144
|
for my $namespace (@namespaces) { |
109
|
19
|
|
|
|
|
45
|
my $can_class = $namespace.'::'.$module; |
110
|
19
|
50
|
|
|
|
103
|
if (can_load( modules => { $can_class, 0 } )) { |
111
|
19
|
|
|
|
|
1405
|
$class = $can_class; |
112
|
19
|
|
|
|
|
76
|
last; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
19
|
50
|
|
|
|
56
|
die __PACKAGE__." can't load validator for ".$key unless $class; |
117
|
19
|
|
|
|
|
86
|
return $self->load_class_cache->{$key} = use_module($class); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub validate { |
121
|
43
|
|
|
43
|
1
|
98
|
my ( $self, %params ) = @_; |
122
|
43
|
|
|
|
|
50
|
my @validators = @{$self->validators}; |
|
43
|
|
|
|
|
747
|
|
123
|
43
|
|
|
|
|
222
|
my @messages; |
124
|
43
|
|
|
|
|
67
|
for my $validator (@validators) { |
125
|
43
|
|
|
|
|
165
|
push @messages, $validator->validate(%params); |
126
|
|
|
|
|
|
|
} |
127
|
43
|
|
|
|
|
557
|
return @messages; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=pod |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 NAME |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Syccess::Field - Syccess field |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 VERSION |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
version 0.103 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 DESCRIPTION |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This class will be used to gather all the validator objects for a specific |
147
|
|
|
|
|
|
|
field of your L<Syccess> definition. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 name |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This attribute is your name for the field given on the L<Syccess> definition. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 label |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
If not set via the validators (See L<Syccess/Label Concept>), this will be |
158
|
|
|
|
|
|
|
calculated out of the L</name>, which was given on the L<Syccess/fields> |
159
|
|
|
|
|
|
|
definition. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 validators |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Contains all the L<Syccess::Validator> object that are generated by the |
164
|
|
|
|
|
|
|
fields definition on the creation of the L<Syccess> object. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 METHODS |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 validate |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This function is called by L<Syccess/validate>, and will by itself then call |
171
|
|
|
|
|
|
|
I<validate> for all the validators of the field and gather the error messages |
172
|
|
|
|
|
|
|
and give them back in return. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=encoding utf8 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 SUPPORT |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
IRC |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Join #sycontent on irc.perl.org. Highlight Getty for fast reaction :). |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Repository |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
http://github.com/SyContent/Syccess |
185
|
|
|
|
|
|
|
Pull request and additional contributors are welcome |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Issue Tracker |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
http://github.com/SyContent/Syccess/issues |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 AUTHOR |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Torsten Raudssus <torsten@raudss.us> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Torsten Raudssus. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
202
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=cut |