1Declare::Constraints::SUismeprleCD:oe:ncLtlirabirrbeau:rt:yeC:do:nOPspeterrrlaaitDnootrcssu:(m:3eS)nitmaptlieo:n:Library::Operators(3)
2
3
4

NAME

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

SYNOPSIS

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

DESCRIPTION

31       This module contains the frameworks operators. These constraint like
32       elements act on the validity of passed constraints.
33

OPERATORS

35   And(@constraints)
36       Is true if all passed @constraints are true on the value. Returns the
37       result of the first failing constraint.
38
39   Or(@constraints)
40       Is true if at least one of the passed @contraints is true. Returns the
41       last failing constraint's result if false.
42
43   XOr(@constraints)
44       Valid only if a single one of the passed @constraints is valid. Returns
45       the last failing constraint's result if false.
46
47   Not($constraint)
48       This is valid if the passed $constraint is false. The main purpose of
49       this operator is to allow the easy reversion of a constraint's
50       trueness.
51
52   CaseValid($test, $conseq, $test2, $conseq2, ...)
53       This runs every given $test argument on the value, until it finds one
54       that returns true. If none is found, false is returned. On a true
55       result, howver, the corresponding $conseq constraint is applied to the
56       value and it's result returned. This allows validation depending on
57       other properties of the value:
58
59         my $flexible = CaseValid( IsArrayRef,
60                                     And( HasArraySize(1,5),
61                                          OnArrayElements(0 => IsInt) ),
62                                   IsHashRef,
63                                     And( HasHashElements(qw( head tail )),
64                                          OnHashKeys(head => IsInt) ));
65
66       Of course, you could model most of it probably with the other
67       operators, but this is a bit more readable. For default cases use
68       "ReturnTrue" from Declare::Constraints::Simple::Library::General as
69       test.
70

SEE ALSO

72       Declare::Constraints::Simple, Declare::Constraints::Simple::Library
73

AUTHOR

75       Robert 'phaylon' Sedlacek "<phaylon@dunkelheit.at>"
76
78       This module is free software, you can redistribute it and/or modify it
79       under the same terms as perl itself.
80
81
82
83perl v5.28.1               Declare2:0:0C6o-n0s9t-r1a4ints::Simple::Library::Operators(3)
Impressum