line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Generic Container Class for a Hash Reference |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Validation::Class::Mapping; |
4
|
|
|
|
|
|
|
|
5
|
109
|
|
|
109
|
|
702
|
use strict; |
|
109
|
|
|
|
|
185
|
|
|
109
|
|
|
|
|
2486
|
|
6
|
109
|
|
|
109
|
|
448
|
use warnings; |
|
109
|
|
|
|
|
185
|
|
|
109
|
|
|
|
|
2583
|
|
7
|
|
|
|
|
|
|
|
8
|
109
|
|
|
109
|
|
5001
|
use Validation::Class::Util '!has', '!hold'; |
|
109
|
|
|
|
|
202
|
|
|
109
|
|
|
|
|
623
|
|
9
|
109
|
|
|
109
|
|
42948
|
use Hash::Merge (); |
|
109
|
|
|
|
|
441781
|
|
|
109
|
|
|
|
|
115182
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '7.900058'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
|
|
|
|
|
|
|
17
|
6584
|
|
|
6584
|
1
|
424924
|
my $class = shift; |
18
|
|
|
|
|
|
|
|
19
|
6584
|
100
|
|
|
|
13550
|
$class = ref $class if ref $class; |
20
|
|
|
|
|
|
|
|
21
|
6584
|
|
|
|
|
15352
|
my $arguments = $class->build_args(@_); |
22
|
|
|
|
|
|
|
|
23
|
6584
|
|
|
|
|
11541
|
my $self = bless {}, $class; |
24
|
|
|
|
|
|
|
|
25
|
6584
|
|
|
|
|
15200
|
$self->add($arguments); |
26
|
|
|
|
|
|
|
|
27
|
6584
|
|
|
|
|
26085
|
return $self; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub add { |
33
|
|
|
|
|
|
|
|
34
|
23888
|
|
|
23888
|
1
|
194770
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
23888
|
|
|
|
|
40707
|
my $arguments = $self->build_args(@_); |
37
|
|
|
|
|
|
|
|
38
|
23888
|
|
|
|
|
31323
|
while (my ($key, $value) = each %{$arguments}) { |
|
65182
|
|
|
|
|
128634
|
|
39
|
|
|
|
|
|
|
|
40
|
41294
|
|
|
|
|
66149
|
$self->{$key} = $value; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
23888
|
|
|
|
|
46940
|
return $self; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub clear { |
50
|
|
|
|
|
|
|
|
51
|
1984
|
|
|
1984
|
1
|
3235
|
my ($self) = @_; |
52
|
|
|
|
|
|
|
|
53
|
1984
|
|
|
|
|
2530
|
$self->delete($_) for keys %{$self}; |
|
1984
|
|
|
|
|
4426
|
|
54
|
|
|
|
|
|
|
|
55
|
1984
|
|
|
|
|
4839
|
return $self; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub count { |
61
|
|
|
|
|
|
|
|
62
|
1973
|
|
|
1973
|
1
|
3649
|
my ($self) = @_; |
63
|
|
|
|
|
|
|
|
64
|
1973
|
|
|
|
|
3645
|
return scalar($self->keys); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub delete { |
70
|
|
|
|
|
|
|
|
71
|
2191
|
|
|
2191
|
1
|
3100
|
my ($self, $name) = @_; |
72
|
|
|
|
|
|
|
|
73
|
2191
|
|
|
|
|
7273
|
return delete $self->{$name}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub defined { |
79
|
|
|
|
|
|
|
|
80
|
136300
|
|
|
136300
|
1
|
174197
|
my ($self, $index) = @_; |
81
|
|
|
|
|
|
|
|
82
|
136300
|
|
|
|
|
371471
|
return defined $self->{$index}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub each { |
88
|
|
|
|
|
|
|
|
89
|
32
|
|
|
32
|
1
|
173
|
my ($self, $code) = @_; |
90
|
|
|
|
|
|
|
|
91
|
32
|
|
50
|
0
|
|
85
|
$code ||= sub {}; |
92
|
|
|
|
|
|
|
|
93
|
32
|
|
|
|
|
62
|
while (my @args = each(%{$self})) { |
|
79
|
|
|
|
|
222
|
|
94
|
|
|
|
|
|
|
|
95
|
47
|
|
|
|
|
103
|
$code->(@args); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
32
|
|
|
|
|
64
|
return $self; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub exists { |
105
|
|
|
|
|
|
|
|
106
|
59211
|
|
|
59211
|
1
|
80761
|
my ($self, $name) = @_; |
107
|
|
|
|
|
|
|
|
108
|
59211
|
100
|
|
|
|
166452
|
return exists $self->{$name} ? 1 : 0; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub get { |
114
|
|
|
|
|
|
|
|
115
|
165687
|
|
|
165687
|
1
|
226326
|
my ($self, $name) = @_; |
116
|
|
|
|
|
|
|
|
117
|
165687
|
|
|
|
|
317559
|
return $self->{$name}; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub grep { |
123
|
|
|
|
|
|
|
|
124
|
1541
|
|
|
1541
|
1
|
2996
|
my ($self, $pattern) = @_; |
125
|
|
|
|
|
|
|
|
126
|
1541
|
50
|
|
|
|
4962
|
$pattern = qr/$pattern/ unless "REGEXP" eq uc ref $pattern; |
127
|
|
|
|
|
|
|
|
128
|
1541
|
|
|
|
|
3816
|
return $self->new(map {$_=>$self->get($_)}grep{$_=~$pattern}($self->keys)); |
|
0
|
|
|
|
|
0
|
|
|
5120
|
|
|
|
|
18313
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub has { |
134
|
|
|
|
|
|
|
|
135
|
136300
|
|
|
136300
|
1
|
184231
|
my ($self, $name) = @_; |
136
|
|
|
|
|
|
|
|
137
|
136300
|
100
|
100
|
|
|
181616
|
return ($self->defined($name) || $self->exists($name)) ? 1 : 0; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub hash { |
143
|
|
|
|
|
|
|
|
144
|
21610
|
|
|
21610
|
1
|
30071
|
my ($self) = @_; |
145
|
|
|
|
|
|
|
|
146
|
21610
|
|
|
|
|
35185
|
return {$self->list}; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub iterator { |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
0
|
1
|
0
|
my ($self, $function, @arguments) = @_; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$function = 'keys' |
156
|
0
|
0
|
|
|
|
0
|
unless grep { $function eq $_ } ('sort', 'rsort', 'nsort', 'rnsort'); |
|
0
|
|
|
|
|
0
|
|
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
my @keys = ($self->$function(@arguments)); |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
0
|
my $i = 0; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
return sub { |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
0
|
|
0
|
return unless defined $keys[$i]; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
0
|
return $self->get($keys[$i++]); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
0
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub keys { |
174
|
|
|
|
|
|
|
|
175
|
13797
|
|
|
13797
|
1
|
19540
|
my ($self) = @_; |
176
|
|
|
|
|
|
|
|
177
|
13797
|
|
|
|
|
15731
|
return (keys(%{$self->hash})); |
|
13797
|
|
|
|
|
21862
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub list { |
183
|
|
|
|
|
|
|
|
184
|
21610
|
|
|
21610
|
1
|
28166
|
my ($self) = @_; |
185
|
|
|
|
|
|
|
|
186
|
21610
|
|
|
|
|
24394
|
return (%{$self}); |
|
21610
|
|
|
|
|
153099
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub merge { |
192
|
|
|
|
|
|
|
|
193
|
1792
|
|
|
1792
|
1
|
2571
|
my $self = shift; |
194
|
|
|
|
|
|
|
|
195
|
1792
|
|
|
|
|
3621
|
my $arguments = $self->build_args(@_); |
196
|
|
|
|
|
|
|
|
197
|
1792
|
|
|
|
|
5010
|
my $merger = Hash::Merge->new('LEFT_PRECEDENT'); |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
# eval bug in Hash::Merge (v0.12 line 100) will likely never be fixed |
200
|
|
|
|
|
|
|
# https://rt.cpan.org/Public/Bug/Display.html?id=55978 |
201
|
|
|
|
|
|
|
# something is hijacking $SIG{__DIE__} |
202
|
1792
|
|
|
|
|
93293
|
eval { $self->add($merger->merge($arguments, $self->hash)) }; |
|
1792
|
|
|
|
|
3676
|
|
203
|
|
|
|
|
|
|
|
204
|
1792
|
|
|
|
|
43787
|
return $self; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub nsort { |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
0
|
|
0
|
my $code = sub { $_[0] <=> $_[1] }; |
|
0
|
|
|
|
|
0
|
|
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
0
|
return $self->sort($code); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub pairs { |
221
|
|
|
|
|
|
|
|
222
|
598
|
|
|
598
|
1
|
1016
|
my ($self, $function, @arguments) = @_; |
223
|
|
|
|
|
|
|
|
224
|
598
|
|
50
|
|
|
1941
|
$function ||= 'keys'; |
225
|
|
|
|
|
|
|
|
226
|
598
|
|
|
|
|
1213
|
my @keys = ($self->$function(@arguments)); |
227
|
|
|
|
|
|
|
|
228
|
598
|
|
|
|
|
1288
|
my @pairs = map {{ key => $_, value => $self->get($_) }} (@keys); |
|
3117
|
|
|
|
|
4533
|
|
229
|
|
|
|
|
|
|
|
230
|
598
|
|
|
|
|
1739
|
return (@pairs); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub rmerge { |
236
|
|
|
|
|
|
|
|
237
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
0
|
my $arguments = $self->build_args(@_); |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
0
|
my $merger = Hash::Merge->new('RIGHT_PRECEDENT'); |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# eval bug in Hash::Merge (v0.12 line 100) will likely never be fixed |
244
|
|
|
|
|
|
|
# https://rt.cpan.org/Public/Bug/Display.html?id=55978 |
245
|
|
|
|
|
|
|
# something is hijacking $SIG{__DIE__} |
246
|
0
|
|
|
|
|
0
|
eval { $self->add($merger->merge($arguments, $self->hash)) }; |
|
0
|
|
|
|
|
0
|
|
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
|
|
0
|
return $self; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub rnsort { |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
0
|
|
0
|
my $code = sub { $_[1] <=> $_[0] }; |
|
0
|
|
|
|
|
0
|
|
258
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
0
|
return $self->sort($code); |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
sub rsort { |
265
|
|
|
|
|
|
|
|
266
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
267
|
|
|
|
|
|
|
|
268
|
0
|
|
|
0
|
|
0
|
my $code = sub { $_[1] cmp $_[0] }; |
|
0
|
|
|
|
|
0
|
|
269
|
|
|
|
|
|
|
|
270
|
0
|
|
|
|
|
0
|
return $self->sort($code); |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub sort { |
276
|
|
|
|
|
|
|
|
277
|
2
|
|
|
2
|
1
|
6
|
my ($self, $code) = @_; |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
return "CODE" eq ref $code ? |
280
|
2
|
50
|
|
|
|
12
|
sort { $a->$code($b) } ($self->keys) : sort { $a cmp $b } ($self->keys); |
|
0
|
|
|
|
|
0
|
|
|
10
|
|
|
|
|
18
|
|
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
sub values { |
286
|
|
|
|
|
|
|
|
287
|
2646
|
|
|
2646
|
1
|
4769
|
my ($self) = @_; |
288
|
|
|
|
|
|
|
|
289
|
2646
|
|
|
|
|
3448
|
return (values(%{$self->hash})); |
|
2646
|
|
|
|
|
5786
|
|
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
1; |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
__END__ |