1Declare::Constraints::SUismeprleC:o:nDLteircbilrbaaurrteye::d::CGPoeennrseltrraDaloi(cn3ut)mse:n:tSaitmipolne::Library::General(3)
2
3
4
6 Declare::Constraints::Simple::Library::General - General Constraints
7
9 # custom error messages
10 my $constraint =
11 And( Message( 'You need to specify a Value', IsDefined ),
12 Message( 'The specified Value is not an Int', IsInt ));
13
14 # build results
15 my $valid = ReturnTrue;
16 my $invalid = ReturnFalse('Just because');
17
19 This library is meant to contain those constraints and constraint-like
20 elements that apply generally to the whole framework.
21
23 Message($message, $constraint)
24 Overrides the "message" set on the result object for failures in
25 $constraint. For example:
26
27 my $message = 'How hard is it to give me a number?';
28 my $constraint = Message($message, IsNumber);
29
30 my $result = $constraint->('duh...');
31 print $result->message, "\n";
32
33 The "Message" constraint overrides the error message returned by it's
34 whole subtree, however, the "Message" specification nearest to the
35 point of failure will win. So while this
36
37 my $constraint = Message( 'Foo',
38 IsArrayRef( Message( 'Bar', IsInt )));
39
40 my $result = $constraint->(['I am not an Integer']);
41 print $result->message;
42
43 will print "Bar", this
44
45 my $result = $constraint->('I\'m not even an ArrayRef');
46 print $result->message;
47
48 will output "Foo".
49
50 Scope($name, $constraint)
51 Executes the passed $constraint in a newly generated scope named $name.
52
53 SetResult($scope, $name, $constraint)
54 Stores the result ov an evaluation of $constraint in $scope under
55 $name.
56
57 IsValid($scope, $name)
58 Returns a true result if the result $name, which has to have been
59 stored previously in the scope named $scope, was valid.
60
61 ReturnTrue()
62 Returns a true result.
63
64 ReturnFalse($msg)
65 Returns a false result containing $msg as error message.
66
68 Declare::Constraints::Simple, Declare::Constraints::Simple::Library
69
71 Robert 'phaylon' Sedlacek "<phaylon@dunkelheit.at>"
72
74 This module is free software, you can redistribute it and/or modify it
75 under the same terms as perl itself.
76
77
78
79perl v5.36.0 Decla2r0e2:2:-C0o7n-s2t2raints::Simple::Library::General(3)