Data/Sah/Compiler/human/TH/hash.pm

filter: Statementstmt 93.5% 173 / 185 Branchbran 50.0% 12 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 26 / 26 Podpod 0.0% 0 / 21 totaltotal 82.4% 211 / 256 CC 23 SCAR 9.9
CC
23
Cov
89%
clause_dep_any
4.2
clause_dep_all
4.2
clause_req_dep_any
4.2
CRAP 2.7
« Test/Data/Sah/Human.pm ↑ Summary Data/Sah/Compiler/human/TH/float.pm »
1 package Data::Sah::Compiler::human::TH::hash;
2  
3 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use Log::Any '$log';
7  
8 4 ▶use Mo qw(build default);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 extends 'Data::Sah::Compiler::human::TH';
12 4 with 'Data::Sah::Compiler::human::TH::Comparable';
13 4 with 'Data::Sah::Compiler::human::TH::HasElems';
14 4 with 'Data::Sah::Type::hash';
15  
16 4 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
17 4 our $DATE = '2024-02-16'; # DATE
18 4 our $DIST = 'Data-Sah'; # DIST
19 4 our $VERSION = '0.917'; # VERSION
20  
21 743 ▶sub handle_type {
Subroutine handle_type: called CC=1 SCAR=0.0
Pod undocumented
22 743 my ($self, $cd) = @_;
23 743 my $c = $self->compiler;
24  
25 743 $c->add_ccl($cd, {
26 fmt => ["hash", "hashes"],
27 type => 'noun',
28 });
29 }
30  
31 12 ▶sub clause_has {
Subroutine clause_has: called CC=1 SCAR=0.0
Pod undocumented
32 12 my ($self, $cd) = @_;
33 12 my $c = $self->compiler;
34  
35 12 $c->add_ccl($cd, {
36 expr=>1, multi=>1,
37 fmt => "%(modal_verb)s have %s in its %(field)s values"});
38 }
39  
40 12 ▶sub clause_each_index {
Subroutine clause_each_index: called CC=1 SCAR=0.0
Pod undocumented
41 12 my ($self, $cd) = @_;
42 12 my $c = $self->compiler;
43 12 my $cv = $cd->{cl_value};
44  
45 12 my %iargs = %{$cd->{args}};
46 12 $iargs{outer_cd} = $cd;
47 12 $iargs{schema} = $cv;
48 12 $iargs{schema_is_normalized} = 0;
49 12 $iargs{cache} = $cd->{args}{cache};
50 12 my $icd = $c->compile(%iargs);
51  
52 $c->add_ccl($cd, {
53 type => 'list',
54 fmt => '%(field)s name %(modal_verb)s be',
55 items => [
56 $icd->{ccls},
57 12 ],
58 vals => [],
59 });
60 }
61  
62 18 ▶sub clause_each_elem {
Subroutine clause_each_elem: called CC=1 SCAR=0.0
Pod undocumented
63 18 my ($self, $cd) = @_;
64 18 my $c = $self->compiler;
65 18 my $cv = $cd->{cl_value};
66  
67 18 my %iargs = %{$cd->{args}};
68 18 $iargs{outer_cd} = $cd;
69 18 $iargs{schema} = $cv;
70 18 $iargs{schema_is_normalized} = 0;
71 18 $iargs{cache} = $cd->{args}{cache};
72 18 my $icd = $c->compile(%iargs);
73  
74 $c->add_ccl($cd, {
75 type => 'list',
76 fmt => 'each %(field)s %(modal_verb)s be',
77 items => [
78 $icd->{ccls},
79 18 ],
80 vals => [],
81 });
82 }
83  
84 47 ▶sub clause_keys {
Subroutine clause_keys: called CC=2 SCAR=6.9
Pod undocumented
85 47 my ($self, $cd) = @_;
86 47 my $c = $self->compiler;
87 47 my $cv = $cd->{cl_value};
88  
89 47 for my $k (sort keys %$cv) {
90 93 local $cd->{spath} = [@{$cd->{spath}}, $k];
91 93 my $v = $cv->{$k};
92 93 my %iargs = %{$cd->{args}};
93 93 $iargs{outer_cd} = $cd;
94 93 $iargs{schema} = $v;
95 93 $iargs{schema_is_normalized} = 0;
96 93 $iargs{cache} = $cd->{args}{cache};
97 93 my $icd = $c->compile(%iargs);
98 $c->add_ccl($cd, {
99 type => 'list',
100 fmt => '%(field)s %s %(modal_verb)s be',
101 vals => [$k],
102 93 items => [ $icd->{ccls} ],
103 });
104 }
105 }
106  
107 9 ▶sub clause_re_keys {
Subroutine clause_re_keys: called CC=2 SCAR=6.9
Pod undocumented
108 9 my ($self, $cd) = @_;
109 9 my $c = $self->compiler;
110 9 my $cv = $cd->{cl_value};
111  
112 9 for my $k (sort keys %$cv) {
113 9 local $cd->{spath} = [@{$cd->{spath}}, $k];
114 9 my $v = $cv->{$k};
115 9 my %iargs = %{$cd->{args}};
116 9 $iargs{outer_cd} = $cd;
117 9 $iargs{schema} = $v;
118 9 $iargs{schema_is_normalized} = 0;
119 9 $iargs{cache} = $cd->{args}{cache};
120 9 my $icd = $c->compile(%iargs);
121 $c->add_ccl($cd, {
122 type => 'list',
123 fmt => '%(fields)s whose names match regex pattern %s %(modal_verb)s be',
124 vals => [$k],
125 9 items => [ $icd->{ccls} ],
126 });
127 }
128 }
129  
130 45 ▶sub clause_req_keys {
Subroutine clause_req_keys: called CC=1 SCAR=0.0
Pod undocumented
131 45 my ($self, $cd) = @_;
132 45 my $c = $self->compiler;
133  
134 45 $c->add_ccl($cd, {
135 fmt => q[%(modal_verb)s have required %(fields)s %s],
136 expr => 1,
137 });
138 }
139  
140 9 ▶sub clause_allowed_keys {
Subroutine clause_allowed_keys: called CC=1 SCAR=0.0
Pod undocumented
141 9 my ($self, $cd) = @_;
142 9 my $c = $self->compiler;
143  
144 9 $c->add_ccl($cd, {
145 fmt => q[%(modal_verb)s only have these allowed %(fields)s %s],
146 expr => 1,
147 });
148 }
149  
150 9 ▶sub clause_allowed_keys_re {
Subroutine clause_allowed_keys_re: called CC=1 SCAR=0.0
Pod undocumented
151 9 my ($self, $cd) = @_;
152 9 my $c = $self->compiler;
153  
154 9 $c->add_ccl($cd, {
155 fmt => q[%(modal_verb)s only have %(fields)s matching regex pattern %s],
156 expr => 1,
157 });
158 }
159  
160 9 ▶sub clause_forbidden_keys {
Subroutine clause_forbidden_keys: called CC=1 SCAR=0.0
Pod undocumented
161 9 my ($self, $cd) = @_;
162 9 my $c = $self->compiler;
163  
164 9 $c->add_ccl($cd, {
165 fmt => q[%(modal_verb_neg)s have these forbidden %(fields)s %s],
166 expr => 1,
167 });
168 }
169  
170 9 ▶sub clause_forbidden_keys_re {
Subroutine clause_forbidden_keys_re: called CC=1 SCAR=0.0
Pod undocumented
171 9 my ($self, $cd) = @_;
172 9 my $c = $self->compiler;
173  
174 9 $c->add_ccl($cd, {
175 fmt => q[%(modal_verb_neg)s have %(fields)s matching regex pattern %s],
176 expr => 1,
177 });
178 }
179  
180 36 ▶sub clause_choose_one_key {
Subroutine clause_choose_one_key: called CC=3 SCAR=11.2
Pod undocumented
181 36 my ($self, $cd) = @_;
182 36 my $c = $self->compiler;
183  
184 36 my $multi = $cd->{cl_is_multi};
185 36 $cd->{cl_is_multi} = 0;
186  
187 36 my @ccls;
188 0 ▶ for my $cv ($multi ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 0 36 36
189 36 push @ccls, {
190 fmt => q[%(modal_verb)s contain at most one of these %(fields)s %s],
191 vals => [$cv],
192 };
193 }
194 36 $c->add_ccl($cd, @ccls);
195 }
196  
197 36 ▶sub clause_choose_all_keys {
Subroutine clause_choose_all_keys: called CC=3 SCAR=11.2
Pod undocumented
198 36 my ($self, $cd) = @_;
199 36 my $c = $self->compiler;
200  
201 36 my $multi = $cd->{cl_is_multi};
202 36 $cd->{cl_is_multi} = 0;
203  
204 36 my @ccls;
205 0 ▶ for my $cv ($multi ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 0 36 36
206 36 push @ccls, {
207 fmt => q[%(modal_verb)s contain either none or all of these %(fields)s %s],
208 vals => [$cv],
209 };
210 }
211 36 $c->add_ccl($cd, @ccls);
212 }
213  
214 24 ▶sub clause_req_one_key {
Subroutine clause_req_one_key: called CC=3 SCAR=11.2
Pod undocumented
215 24 my ($self, $cd) = @_;
216 24 my $c = $self->compiler;
217  
218 24 my $multi = $cd->{cl_is_multi};
219 24 $cd->{cl_is_multi} = 0;
220  
221 24 my @ccls;
222 0 ▶ for my $cv ($multi ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 0 24 24
223 24 push @ccls, {
224 fmt => q[%(modal_verb)s contain exactly one of these %(fields)s %s],
225 vals => [$cv],
226 };
227 }
228 24 $c->add_ccl($cd, @ccls);
229 }
230  
231 60 ▶sub clause_req_some_keys {
Subroutine clause_req_some_keys: called CC=3 SCAR=11.2
Pod undocumented
232 60 my ($self, $cd) = @_;
233 60 my $c = $self->compiler;
234  
235 60 my $multi = $cd->{cl_is_multi};
236 60 $cd->{cl_is_multi} = 0;
237  
238 60 my @ccls;
239 0 ▶ for my $cv ($multi ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 0 60 60
240 60 push @ccls, {
241 fmt => q[%(modal_verb)s contain between %d and %d of these %(fields)s %s],
242 vals => [$cv->[0], $cv->[1], $cv->[2]],
243 };
244 }
245 60 $c->add_ccl($cd, @ccls);
246 }
247  
248 18 ▶sub clause_dep_any {
Subroutine clause_dep_any: called CC=4 SCAR=14.5
Pod undocumented
249 18 my ($self, $cd) = @_;
250 18 my $c = $self->compiler;
251  
252 18 my $multi = $cd->{cl_is_multi};
253 18 $cd->{cl_is_multi} = 0;
254  
255 18 my @ccls;
256 0 ▶ for my $cv ($multi ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 0 18 18
257 18 ▶ if (@{ $cv->[1] } == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$cv->[1];} == 1) { } 0 18 18
258 0 push @ccls, {
259 fmt => q[%(field)s %2$s %(modal_verb)s be present before %(field)s %1$s can be present],
260 vals => [$cv->[0], $cv->[1][0]],
261 };
262 } else {
263 18 push @ccls, {
264 fmt => q[one of %(fields)s %2$s %(modal_verb)s be present before %(field)s %1$s can be present],
265 vals => $cv,
266 multi => 0,
267 };
268 }
269 }
270 18 $c->add_ccl($cd, @ccls);
271 }
272  
273 18 ▶sub clause_dep_all {
Subroutine clause_dep_all: called CC=4 SCAR=14.5
Pod undocumented
274 18 my ($self, $cd) = @_;
275 18 my $c = $self->compiler;
276  
277 18 my $multi = $cd->{cl_is_multi};
278 18 $cd->{cl_is_multi} = 0;
279  
280 18 my @ccls;
281 0 ▶ for my $cv ($multi ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 0 18 18
282 18 ▶ if (@{ $cv->[1] } == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$cv->[1];} == 1) { } 0 18 18
283 0 push @ccls, {
284 fmt => q[%(field)s %2$s %(modal_verb)s be present before %(field)s %1$s can be present],
285 vals => [$cv->[0], $cv->[1][0]],
286 };
287 } else {
288 18 push @ccls, {
289 fmt => q[all of %(fields)s %2$s %(modal_verb)s be present before %(field)s %1$s can be present],
290 vals => $cv,
291 };
292 }
293 }
294 18 $c->add_ccl($cd, @ccls);
295 }
296  
297 24 ▶sub clause_req_dep_any {
Subroutine clause_req_dep_any: called CC=4 SCAR=14.5
Pod undocumented
298 24 my ($self, $cd) = @_;
299 24 my $c = $self->compiler;
300  
301 24 my $multi = $cd->{cl_is_multi};
302 24 $cd->{cl_is_multi} = 0;
303  
304 24 my @ccls;
305 0 ▶ for my $cv ($multi ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 0 24 24
306 24 ▶ if (@{ $cv->[1] } == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$cv->[1];} == 1) { } 0 24 24
307 0 push @ccls, {
308 fmt => q[%(field)s %1$s %(modal_verb)s be present when %(field)s %2$s is present],
309 vals => [$cv->[0], $cv->[1][0]],
310 };
311 } else {
312 24 push @ccls, {
313 fmt => q[%(field)s %1$s %(modal_verb)s be present when one of %(fields)s %2$s is present],
314 vals => $cv,
315 };
316 }
317 }
318 24 $c->add_ccl($cd, @ccls);
319 }
320  
321 24 ▶sub clause_req_dep_all {
Subroutine clause_req_dep_all: called CC=4 SCAR=14.5
Pod undocumented
322 24 my ($self, $cd) = @_;
323 24 my $c = $self->compiler;
324  
325 24 my $multi = $cd->{cl_is_multi};
326 24 $cd->{cl_is_multi} = 0;
327  
328 24 my @ccls;
329 0 ▶ for my $cv ($multi ? @{ $cd->{cl_value} } : ($cd->{cl_value})) {
Branch: 1 branch
BranchTrueFalseTotal
$multi ? : 0 24 24
330 24 ▶ if (@{ $cv->[1] } == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$cv->[1];} == 1) { } 0 24 24
331 0 push @ccls, {
332 fmt => q[%(field)s %1$s %(modal_verb)s be present when %(field)s %2$s is present],
333 vals => [$cv->[0], $cv->[1][0]],
334 };
335 } else {
336 24 push @ccls, {
337 fmt => q[%(field)s %1$s %(modal_verb)s be present when all of %(fields)s %2$s are present],
338 vals => $cv,
339 };
340 }
341 }
342 24 $c->add_ccl($cd, @ccls);
343 }
344  
345 47 ▶sub after_clause_keys {
Subroutine after_clause_keys: called CC=1 SCAR=0.0
Pod undocumented
346 47 my ($self, $cd) = @_;
347  
348 # ignored attributes
349 47 delete $cd->{uclset}{'keys.restrict'};
350 47 delete $cd->{uclset}{'keys.create_default'};
351 }
352  
353 9 ▶sub after_clause_re_keys {
Subroutine after_clause_re_keys: called CC=1 SCAR=0.0
Pod undocumented
354 9 my ($self, $cd) = @_;
355  
356 # ignored attributes
357 9 delete $cd->{uclset}{'re_keys.restrict'};
358 }
359  
360 4 1;
361 # ABSTRACT: human's type handler for type "hash"
362  
363 __END__
« Test/Data/Sah/Human.pm ↑ Summary Data/Sah/Compiler/human/TH/float.pm »