1Declare::Constraints::SUismeprleC:o:nLtirbiDrbeaucrtlyea:dr:eHP:ae:srChlo(n3Ds)otcruamiennttsa:t:iSoinmple::Library::Hash(3)
2
3
4

NAME

6       Declare::Constraints::Simple::Library::Hash - Hash Constraints
7

SYNOPSIS

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

DESCRIPTION

20       This module contains all constraints that can be applied to hash refer‐
21       ences.
22
23       HasAllKeys(@keys)
24
25       The value has to be a hashref, and contain all keys listed in @keys to
26       pass this constraint.
27
28       The stack or path part of "HasAllKeys" is "HasAllKeys[$key]" where $key
29       is the missing key.
30
31       OnHashKeys(key => $constraint, key => $constraint, ...)
32
33       This allows you to pass a constraint for each specific key in a hash
34       reference. If a specified key is not in the validated hash reference,
35       the validation for this key is not done. To make a key a requirement,
36       use HasAllKeys(@keys) above in combination with this, e.g. like:
37
38         And( HasAllKeys( qw(foo bar baz) )
39              OnHashKeys( foo => IsInt,
40                          bar => Matches(qr/bar/),
41                          baz => IsArrayRef( HasLength )));
42
43       Also, as you might see, you don't have to check for "IsHashRef" valid‐
44       ity here. The hash constraints are already doing that by themselves.
45
46       The stack or path part of "OnHashKeys" looks like "OnHashKeys[$key]"
47       where $key is the key of the failing value.
48

SEE ALSO

50       Declare::Constraints::Simple, Declare::Constraints::Simple::Library
51

AUTHOR

53       Robert 'phaylon' Sedlacek "<phaylon@dunkelheit.at>"
54
56       This module is free software, you can redistribute it and/or modify it
57       under the same terms as perl itself.
58
59
60
61perl v5.8.8                     De2c0l0a6r-e0:9:-C1o1nstraints::Simple::Library::Hash(3)
Impressum