line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Context; |
2
|
19
|
|
|
19
|
|
94
|
use strict; |
|
19
|
|
|
|
|
38
|
|
|
19
|
|
|
|
|
622
|
|
3
|
19
|
|
|
19
|
|
85
|
use warnings; |
|
19
|
|
|
|
|
31
|
|
|
19
|
|
|
|
|
582
|
|
4
|
19
|
|
|
19
|
|
81
|
use utf8; |
|
19
|
|
|
|
|
22
|
|
|
19
|
|
|
|
|
123
|
|
5
|
|
|
|
|
|
|
|
6
|
19
|
|
|
19
|
|
8432
|
use Valiemon::ValidationError; |
|
19
|
|
|
|
|
48
|
|
|
19
|
|
|
|
|
848
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
9
|
19
|
|
|
|
|
97
|
ro => [qw(root_validator root_schema errors positions)], |
10
|
19
|
|
|
19
|
|
140
|
); |
|
19
|
|
|
|
|
30
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
109
|
|
|
109
|
0
|
940
|
my ($class, $validator, $schema) = @_; |
14
|
109
|
|
|
|
|
1012
|
return bless { |
15
|
|
|
|
|
|
|
root_validator => $validator, |
16
|
|
|
|
|
|
|
root_schema => $schema, |
17
|
|
|
|
|
|
|
errors => [], |
18
|
|
|
|
|
|
|
positions => [], |
19
|
|
|
|
|
|
|
}, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
133
|
|
|
133
|
0
|
392
|
sub rv { $_[0]->root_validator } |
23
|
0
|
|
|
0
|
0
|
0
|
sub rs { $_[0]->root_schema } |
24
|
|
|
|
|
|
|
|
25
|
262
|
|
|
262
|
0
|
696
|
sub prims { $_[0]->root_validator->prims } # TODO refactor |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub push_error { |
28
|
72
|
|
|
72
|
0
|
114
|
my ($self, $error) = @_; |
29
|
72
|
|
|
|
|
89
|
push @{$self->errors}, $error; |
|
72
|
|
|
|
|
215
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub push_pos { |
33
|
433
|
|
|
433
|
0
|
542
|
my ($self, $pos) = @_; |
34
|
433
|
|
|
|
|
449
|
push @{$self->positions}, $pos; |
|
433
|
|
|
|
|
1099
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub pop_pos { |
38
|
421
|
|
|
421
|
0
|
531
|
my ($self) = @_; |
39
|
421
|
|
|
|
|
396
|
pop @{$self->positions}; |
|
421
|
|
|
|
|
1203
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub is_root { |
43
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
44
|
0
|
0
|
|
|
|
0
|
return scalar @{$self->positions} == 0 ? 1 : 0; |
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub position { |
48
|
84
|
|
|
84
|
0
|
117
|
my ($self) = @_; |
49
|
84
|
|
|
|
|
110
|
return '/' . join '/', @{$self->positions}; |
|
84
|
|
|
|
|
220
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub generate_error { |
53
|
72
|
|
|
72
|
0
|
120
|
my ($self, $attr) = @_; |
54
|
72
|
|
|
|
|
205
|
return Valiemon::ValidationError->new($attr, $self->position); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub in_attr ($&) { |
58
|
334
|
|
|
334
|
0
|
510
|
my ($self, $attr, $code) = @_; |
59
|
334
|
|
|
|
|
1082
|
$self->push_pos($attr->attr_name); |
60
|
334
|
|
|
|
|
2949
|
my $is_valid = $code->(); |
61
|
322
|
100
|
|
|
|
11797
|
my @res = $is_valid ? (1, undef) : (0, $self->generate_error($attr)); |
62
|
322
|
|
|
|
|
744
|
$self->pop_pos(); |
63
|
322
|
|
|
|
|
2454
|
return @res; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub in ($&) { |
67
|
99
|
|
|
99
|
0
|
233
|
my ($self, $pos, $code) = @_; |
68
|
99
|
|
|
|
|
186
|
$self->push_pos($pos); |
69
|
99
|
|
|
|
|
685
|
my $res = $code->(); |
70
|
99
|
|
|
|
|
404
|
$self->pop_pos(); |
71
|
99
|
|
|
|
|
625
|
return $res; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub sub_validator { |
75
|
109
|
|
|
109
|
0
|
296
|
my ($self, $sub_schema) = @_; |
76
|
109
|
|
|
|
|
1080
|
require Valiemon; |
77
|
109
|
|
|
|
|
291
|
return Valiemon->new( |
78
|
|
|
|
|
|
|
$sub_schema, |
79
|
|
|
|
|
|
|
$self->rv->options, # inherit options |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |