GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  DECLARE::CONSTRAINTS::SIMPLE::LIBRARY::HASH (3)

.ds Aq ’

NAME

Declare::Constraints::Simple::Library::Hash - Hash Constraints

CONTENTS

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 is HasAllKeys[$key] where $key is the missing key.

OnHashKeys(key => CW$constraint, key => CW$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 like OnHashKeys[$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.
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 DECLARE::CONSTRAINTS::SIMPLE::LIBRARY::HASH (3) 2006-09-11

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.