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
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

SEE ALSO

49       Declare::Constraints::Simple, Declare::Constraints::Simple::Library
50

AUTHOR

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.28.0                    De2c0l0a6r-e0:9:-C1o1nstraints::Simple::Library::Hash(3)
Impressum