line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Validation; |
2
|
5
|
|
|
5
|
|
2955
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
164
|
|
3
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
128
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
19
|
use Moo; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Articulate::Role::Component'; |
8
|
5
|
|
|
5
|
|
1210
|
use Articulate::Syntax qw(instantiate_array); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
33
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Articulate::Validation - ensure content is valid before accepting it. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
use Articulate::Validation; |
17
|
|
|
|
|
|
|
$validation->validate($item) or throw_error; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Validators should return a true argument if either a) The item is valid, or b) The validator has no opinion on the item. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head3 validate |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Iterates through the validators. Returns false if any has a false result. Returns true otherwise. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 ATTTRIBUTES |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head3 validators |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
An arrayref of the classes which provide a validate function, in the order in which they will be asked to validate items. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has validators => ( |
38
|
|
|
|
|
|
|
is => 'rw', |
39
|
|
|
|
|
|
|
default => sub { [] }, |
40
|
|
|
|
|
|
|
coerce => sub { instantiate_array @_ } |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub validate { |
44
|
5
|
|
|
5
|
1
|
112
|
my $self = shift; |
45
|
5
|
|
|
|
|
7
|
my $item = shift; |
46
|
5
|
|
|
|
|
6
|
foreach my $validator ( @{ $self->validators } ) { |
|
5
|
|
|
|
|
52
|
|
47
|
2
|
|
|
|
|
13
|
my $result = $validator->validate($item); |
48
|
2
|
100
|
|
|
|
9
|
return $result unless $result; |
49
|
|
|
|
|
|
|
} |
50
|
4
|
|
|
|
|
873
|
return 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |