line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Valiemon::Context; |
2
|
25
|
|
|
25
|
|
178
|
use strict; |
|
25
|
|
|
|
|
49
|
|
|
25
|
|
|
|
|
723
|
|
3
|
25
|
|
|
25
|
|
127
|
use warnings; |
|
25
|
|
|
|
|
42
|
|
|
25
|
|
|
|
|
583
|
|
4
|
25
|
|
|
25
|
|
123
|
use utf8; |
|
25
|
|
|
|
|
46
|
|
|
25
|
|
|
|
|
136
|
|
5
|
|
|
|
|
|
|
|
6
|
25
|
|
|
25
|
|
10691
|
use Valiemon::ValidationError; |
|
25
|
|
|
|
|
76
|
|
|
25
|
|
|
|
|
1000
|
|
7
|
|
|
|
|
|
|
|
8
|
25
|
|
|
25
|
|
171
|
use constant ACCESSORS => [qw(root_validator root_schema errors positions)]; |
|
25
|
|
|
|
|
48
|
|
|
25
|
|
|
|
|
3059
|
|
9
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
10
|
25
|
|
|
|
|
98
|
ro => ACCESSORS(), |
11
|
25
|
|
|
25
|
|
183
|
); |
|
25
|
|
|
|
|
47
|
|
12
|
25
|
|
|
25
|
|
13055
|
use Clone qw(clone); |
|
25
|
|
|
|
|
61449
|
|
|
25
|
|
|
|
|
16218
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
695
|
|
|
695
|
0
|
2067
|
my ($class, $validator, $schema) = @_; |
16
|
695
|
|
|
|
|
4592
|
return bless { |
17
|
|
|
|
|
|
|
root_validator => $validator, |
18
|
|
|
|
|
|
|
root_schema => $schema, |
19
|
|
|
|
|
|
|
errors => [], |
20
|
|
|
|
|
|
|
positions => [], |
21
|
|
|
|
|
|
|
}, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub clone_from { |
25
|
44
|
|
|
44
|
0
|
97
|
my ($class, $instance) = @_; |
26
|
|
|
|
|
|
|
return bless { |
27
|
44
|
|
|
|
|
64
|
map { $_ => clone($instance->$_) } @{ACCESSORS()} |
|
176
|
|
|
|
|
3577
|
|
|
44
|
|
|
|
|
91
|
|
28
|
|
|
|
|
|
|
}, $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
406
|
|
|
406
|
0
|
955
|
sub rv { $_[0]->root_validator } |
32
|
0
|
|
|
0
|
0
|
0
|
sub rs { $_[0]->root_schema } |
33
|
|
|
|
|
|
|
|
34
|
977
|
|
|
977
|
0
|
2230
|
sub prims { $_[0]->root_validator->prims } # TODO refactor |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub push_error { |
37
|
383
|
|
|
383
|
0
|
16363
|
my ($self, $error) = @_; |
38
|
383
|
|
|
|
|
595
|
push @{$self->errors}, $error; |
|
383
|
|
|
|
|
791
|
|
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub push_pos { |
42
|
1389
|
|
|
1389
|
0
|
2403
|
my ($self, $pos) = @_; |
43
|
1389
|
|
|
|
|
1871
|
push @{$self->positions}, $pos; |
|
1389
|
|
|
|
|
2972
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub pop_pos { |
47
|
1343
|
|
|
1343
|
0
|
2095
|
my ($self) = @_; |
48
|
1343
|
|
|
|
|
1712
|
pop @{$self->positions}; |
|
1343
|
|
|
|
|
2566
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub is_root { |
52
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
53
|
0
|
0
|
|
|
|
0
|
return scalar @{$self->positions} == 0 ? 1 : 0; |
|
0
|
|
|
|
|
0
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub position { |
57
|
398
|
|
|
398
|
0
|
660
|
my ($self) = @_; |
58
|
398
|
|
|
|
|
590
|
return '/' . join '/', @{$self->positions}; |
|
398
|
|
|
|
|
776
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub generate_error { |
62
|
380
|
|
|
380
|
0
|
797
|
my ($self, $attr) = @_; |
63
|
380
|
|
|
|
|
767
|
return Valiemon::ValidationError->new($attr, $self->position); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub in_attr ($&) { |
67
|
1104
|
|
|
1104
|
0
|
2294
|
my ($self, $attr, $code) = @_; |
68
|
1104
|
|
|
|
|
2905
|
$self->push_pos($attr->attr_name); |
69
|
1104
|
|
|
|
|
7601
|
my $is_valid = $code->(); |
70
|
1066
|
100
|
|
|
|
40475
|
my @res = $is_valid ? (1, undef) : (0, $self->generate_error($attr)); |
71
|
1066
|
|
|
|
|
2617
|
$self->pop_pos(); |
72
|
1066
|
|
|
|
|
7628
|
return @res; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub in ($&) { |
76
|
285
|
|
|
285
|
0
|
561
|
my ($self, $pos, $code) = @_; |
77
|
285
|
|
|
|
|
653
|
$self->push_pos($pos); |
78
|
285
|
|
|
|
|
1865
|
my $res = $code->(); |
79
|
277
|
|
|
|
|
825
|
$self->pop_pos(); |
80
|
277
|
|
|
|
|
1532
|
return $res; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub sub_validator { |
84
|
349
|
|
|
349
|
0
|
604
|
my ($self, $sub_schema) = @_; |
85
|
349
|
|
|
|
|
1834
|
require Valiemon; |
86
|
349
|
|
|
|
|
800
|
return Valiemon->new( |
87
|
|
|
|
|
|
|
$sub_schema, |
88
|
|
|
|
|
|
|
$self->rv->options, # inherit options |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |