1Declare::Constraints::SUismeprleC:o:nLtirbiDrbeaucrtlyea:dr:eHP:ae:srChlo(n3Ds)otcruamiennttsa:t:iSoinmple::Library::Hash(3)
2
3
4
6 Declare::Constraints::Simple::Library::Hash - Hash Constraints
7
9 my $constraint = And(
10
11 # make sure all keys are present
12 HasAllKeys( qw(foo bar) ),
13
14 # constraints for the keys
15 OnHashKeys( foo => IsInt, bar => HasLength )
16
17 );
18
20 This module contains all constraints that can be applied to hash
21 references.
22
23 HasAllKeys(@keys)
24 The value has to be a hashref, and contain all keys listed in @keys to
25 pass this constraint.
26
27 The stack or path part of "HasAllKeys" is "HasAllKeys[$key]" where $key
28 is the missing key.
29
30 OnHashKeys(key => $constraint, key => $constraint, ...)
31 This allows you to pass a constraint for each specific key in a hash
32 reference. If a specified key is not in the validated hash reference,
33 the validation for this key is not done. To make a key a requirement,
34 use HasAllKeys(@keys) above in combination with this, e.g. like:
35
36 And( HasAllKeys( qw(foo bar baz) )
37 OnHashKeys( foo => IsInt,
38 bar => Matches(qr/bar/),
39 baz => IsArrayRef( HasLength )));
40
41 Also, as you might see, you don't have to check for "IsHashRef"
42 validity here. The hash constraints are already doing that by
43 themselves.
44
45 The stack or path part of "OnHashKeys" looks like "OnHashKeys[$key]"
46 where $key is the key of the failing value.
47
49 Declare::Constraints::Simple, Declare::Constraints::Simple::Library
50
52 Robert 'phaylon' Sedlacek "<phaylon@dunkelheit.at>"
53
55 This module is free software, you can redistribute it and/or modify it
56 under the same terms as perl itself.
57
58
59
60perl v5.36.0 De2c0l2a3r-e0:1:-C2o0nstraints::Simple::Library::Hash(3)