line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Interface::Validation Validation Specification |
2
|
|
|
|
|
|
|
package Interface::Validation::Specification; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
141270
|
use Bubblegum; |
|
2
|
|
|
|
|
344444
|
|
|
2
|
|
|
|
|
12
|
|
5
|
2
|
|
|
2
|
|
1613511
|
use Function::Parameters; |
|
2
|
|
|
|
|
7339
|
|
|
2
|
|
|
|
|
16
|
|
6
|
2
|
|
|
2
|
|
1822
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Interface::Validation::Container; |
9
|
|
|
|
|
|
|
use Interface::Validation::Document; |
10
|
|
|
|
|
|
|
use Interface::Validation::Execution; |
11
|
|
|
|
|
|
|
use Interface::Validation::Failure; |
12
|
|
|
|
|
|
|
use Interface::Validation::Field; |
13
|
|
|
|
|
|
|
use Interface::Validation::Mixin; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Bubblegum::Constraints -minimal; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.01_01'; # VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'fields' => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
isa => 'Interface::Validation::Container', |
22
|
|
|
|
|
|
|
default => sub { Interface::Validation::Container->new } |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'mixins' => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
isa => 'Interface::Validation::Container', |
28
|
|
|
|
|
|
|
default => sub { Interface::Validation::Container->new } |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has 'documents' => ( |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
isa => 'Interface::Validation::Container', |
34
|
|
|
|
|
|
|
default => sub { Interface::Validation::Container->new } |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
method document { |
38
|
|
|
|
|
|
|
my $args = {@_ % 2 == 1 ? ('name', @_) : @_}; |
39
|
|
|
|
|
|
|
my $bind = $args->delete('criteria'); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $document = Interface::Validation::Document->new($args); |
42
|
|
|
|
|
|
|
$self->documents->set($document->name, $document); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
if ($bind) { |
45
|
|
|
|
|
|
|
$document->criterion($_, $bind->get($_)) for $bind->keys->list; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $document; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
method execute { |
52
|
|
|
|
|
|
|
# TODO ... |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
method field { |
56
|
|
|
|
|
|
|
my $args = {@_ % 2 == 1 ? ('name', @_) : @_}; |
57
|
|
|
|
|
|
|
my $name = $args->delete('name'); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $field = Interface::Validation::Field->new($name); |
60
|
|
|
|
|
|
|
$self->fields->set($field->name, $field); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
for ($args->keys->list) { |
63
|
|
|
|
|
|
|
$field->directive($_, $args->get($_)) unless $field->can($_); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return $field; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
method mixin { |
70
|
|
|
|
|
|
|
my $args = {@_ % 2 == 1 ? ('name', @_) : @_}; |
71
|
|
|
|
|
|
|
my $name = $args->delete('name'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $mixin = Interface::Validation::Mixin->new($name); |
74
|
|
|
|
|
|
|
$self->mixins->set($mixin->name, $mixin); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
for ($args->keys->list) { |
77
|
|
|
|
|
|
|
$mixin->directive($_, $args->get($_)) unless $mixin->can($_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return $mixin; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
method prepare { |
84
|
|
|
|
|
|
|
# TODO ... |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
method validate { |
88
|
|
|
|
|
|
|
my $document = _defined shift; |
89
|
|
|
|
|
|
|
my $data = _hashref shift; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $gendoc; |
92
|
|
|
|
|
|
|
my @tempfields; |
93
|
|
|
|
|
|
|
if (isa_hashref $document) { |
94
|
|
|
|
|
|
|
my $count = 0; |
95
|
|
|
|
|
|
|
my $criteria = {}; |
96
|
|
|
|
|
|
|
while (my ($key, $value) = each %{$document}) { |
97
|
|
|
|
|
|
|
if (isa_hashref $value) { |
98
|
|
|
|
|
|
|
$count++; |
99
|
|
|
|
|
|
|
push @tempfields, (my $name = "#field_${count}"); |
100
|
|
|
|
|
|
|
$self->field($name => %$value); |
101
|
|
|
|
|
|
|
$criteria->{$key} = $name; |
102
|
|
|
|
|
|
|
} else { |
103
|
|
|
|
|
|
|
$criteria->{$key} = $value; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
$self->document( |
107
|
|
|
|
|
|
|
($document = $gendoc = '#document') => ( |
108
|
|
|
|
|
|
|
criteria => $criteria |
109
|
|
|
|
|
|
|
) |
110
|
|
|
|
|
|
|
); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $exec = Interface::Validation::Execution->new( |
114
|
|
|
|
|
|
|
data => $data, |
115
|
|
|
|
|
|
|
document => $document, |
116
|
|
|
|
|
|
|
specification => $self |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $result = $exec->run(@_); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
if (@tempfields) { |
122
|
|
|
|
|
|
|
$self->fields->delete($_) for @tempfields; |
123
|
|
|
|
|
|
|
$self->documents->delete($gendoc); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
return $result; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |