1Declare::Constraints::SUismeprleCD:oe:ncLtlirabirrbeau:rt:yeC:do:nOPspeterrrlaaitDnootrcssu:(m:3eS)nitmaptlieo:n:Library::Operators(3)
2
3
4
6 Declare::Constraints::Simple::Library::Operators - Operators
7
9 # all hast to be valid
10 my $and_constraint = And( IsInt,
11 Matches(qr/0$/) );
12
13 # at least one has to be valid
14 my $or_constraint = Or( IsInt, HasLength );
15
16 # only one can be valid
17 my $xor_constraint = XOr( IsClass, IsObject );
18
19 # reverse validity
20 my $not_an_integer = Not( IsInt );
21
22 # case valid, validate 'bar' key depending on 'foo' keys value
23 my $struct_prof =
24 And( IsHashRef,
25 CaseValid( OnHashKeys(foo => IsEq("FooArray")),
26 OnHashKeys(bar => IsArrayRef),
27 OnHashKeys(foo => IsEq("FooHash")),
28 OnHashKeys(bar => IsHashRef) ));
29
31 This module contains the frameworks operators. These constraint like
32 elements act on the validity of passed constraints.
33
35 And(@constraints)
36
37 Is true if all passed @constraints are true on the value. Returns the
38 result of the first failing constraint.
39
40 Or(@constraints)
41
42 Is true if at least one of the passed @contraints is true. Returns the
43 last failing constraint's result if false.
44
45 XOr(@constraints)
46
47 Valid only if a single one of the passed @constraints is valid. Returns
48 the last failing constraint's result if false.
49
50 Not($constraint)
51
52 This is valid if the passed $constraint is false. The main purpose of
53 this operator is to allow the easy reversion of a constraint's true‐
54 ness.
55
56 CaseValid($test, $conseq, $test2, $conseq2, ...)
57
58 This runs every given $test argument on the value, until it finds one
59 that returns true. If none is found, false is returned. On a true
60 result, howver, the corresponding $conseq constraint is applied to the
61 value and it's result returned. This allows validation depending on
62 other properties of the value:
63
64 my $flexible = CaseValid( IsArrayRef,
65 And( HasArraySize(1,5),
66 OnArrayElements(0 => IsInt) ),
67 IsHashRef,
68 And( HasHashElements(qw( head tail )),
69 OnHashKeys(head => IsInt) ));
70
71 Of course, you could model most of it probably with the other opera‐
72 tors, but this is a bit more readable. For default cases use "Return‐
73 True" from Declare::Constraints::Simple::Library::General as test.
74
76 Declare::Constraints::Simple, Declare::Constraints::Simple::Library
77
79 Robert 'phaylon' Sedlacek "<phaylon@dunkelheit.at>"
80
82 This module is free software, you can redistribute it and/or modify it
83 under the same terms as perl itself.
84
85
86
87perl v5.8.8 Declare2:0:0C6o-n0s9t-r1a1ints::Simple::Library::Operators(3)