-
-
14 Sep 2006 14:14:18 UTC
- Distribution: Declare-Constraints-Simple
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (3)
- Testers (2628 / 11 / 4)
- Kwalitee
Bus factor: 0- 98.21% Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (29.63KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Robert 'phaylon' Sedlacek
- Dependencies
- Carp::Clan
- Class::Inspector
- Scalar::Util
- aliased
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Declare::Constraints::Simple::Library::Hash - Hash Constraints
SYNOPSIS
my $constraint = And( # make sure all keys are present HasAllKeys( qw(foo bar) ), # constraints for the keys OnHashKeys( foo => IsInt, bar => HasLength ) );
DESCRIPTION
This module contains all constraints that can be applied to hash references.
HasAllKeys(@keys)
The value has to be a hashref, and contain all keys listed in
@keys
to pass this constraint.The stack or path part of
HasAllKeys
isHasAllKeys[$key]
where$key
is the missing key.OnHashKeys(key => $constraint, key => $constraint, ...)
This allows you to pass a constraint for each specific key in a hash reference. If a specified key is not in the validated hash reference, the validation for this key is not done. To make a key a requirement, use HasAllKeys(@keys) above in combination with this, e.g. like:
And( HasAllKeys( qw(foo bar baz) ) OnHashKeys( foo => IsInt, bar => Matches(qr/bar/), baz => IsArrayRef( HasLength )));
Also, as you might see, you don't have to check for
IsHashRef
validity here. The hash constraints are already doing that by themselves.The stack or path part of
OnHashKeys
looks likeOnHashKeys[$key]
where$key
is the key of the failing value.SEE ALSO
Declare::Constraints::Simple, Declare::Constraints::Simple::Library
AUTHOR
Robert 'phaylon' Sedlacek
<phaylon@dunkelheit.at>
LICENSE AND COPYRIGHT
This module is free software, you can redistribute it and/or modify it under the same terms as perl itself.
Module Install Instructions
To install Declare::Constraints::Simple, copy and paste the appropriate command in to your terminal.
cpanm Declare::Constraints::Simple
perl -MCPAN -e shell install Declare::Constraints::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.