1Declare::Constraints::SUismeprleC:o:nLtirbiDrbeaucrtlyea:dr:eBP:ae:srCelo(n3Ds)otcruamiennttsa:t:iSoinmple::Library::Base(3)
2
3
4

NAME

6       Declare::Constraints::Simple::Library::Base - Library Base Class
7

SYNOPSIS

9         package My::Constraint::Library;
10         use warnings;
11         use strict;
12
13         # this installs the base class and helper functions
14         use Declare::Constraints::Simple-Library;
15
16         # we can also automagically provide other libraries
17         # to the importer
18         use base 'Declare::Constraints::Simple::Library::Numericals';
19
20         # with this we define a constraint to check a value
21         # against a serial number regular expression
22         constraint 'SomeSerial',
23           sub {
24             return sub {
25               return _true if $_[0] =~ /\d{3}-\d{3}-\d{4}/;
26               return _false('Not in SomeSerial format');
27             };
28           };
29
30         1;
31

DESCRIPTION

33       This base class contains the common library functionalities. This
34       includes helper functions and install mechanisms.
35

METHODS

37       install_into($target)
38
39       Installs the base classes and helper functions into the $target names‐
40       pace. The %CONSTRAINT_GENERATORS package variable of that class will be
41       used as storage for it's constraints.
42
43       fetch_constraint_declarations()
44
45       Class method. Returns all constraints registered to the class.
46
47       fetch_constraint_generator($name)
48
49       Class method. Returns the constraint generator code reference regis‐
50       tered under $name. The call will raise a "croak" if the generator could
51       not be found.
52
53       prepare_generator($constraint_name, $generator)
54
55       Class method. This wraps the $generator in a closure that provides
56       stack and failure-collapsing decisions.
57
58       add_constraint_generator($name, $code)
59
60       Class method. The actual registration method, used by "constraint".
61

HELPER FUNCTIONS

63       Note that some of the helper functions are prefixed with "_". Although
64       this means they are internal functions, it is ok to call them, as they
65       have a fixed API. They are not distribution internal, but library
66       internal, and only intended to be used from inside constraints.
67
68       constraint($name, $code)
69
70         constraint 'Foo', sub { ... };
71
72       This registers a new constraint in the calling library. Note that con‐
73       straints have to return result objects. To do this, you can use the
74       helper functions "_result($bool, $msg", _true() and _false($msg).
75
76       _result($bool, $msg)
77
78       Returns a new result object. It's validity flag will depend on the
79       $bool argument. The $msg argument is the error message to use on fail‐
80       ure.
81
82       _false($msg)
83
84       Returns a non-valid result object, with it's message set to $msg.
85
86       _true()
87
88       Returns a valid result object.
89
90       _info($info)
91
92       Sets the current failure info to use in the stack info part.
93
94       _apply_checks($value, \@constraints, [$info])
95
96       This applies all constraints in the "\@constraints" array reference to
97       the passed $value. You can optionally specify an $info string to be
98       used in the stack of the newly created non-valid results.
99
100       _listify($value)
101
102       Puts $value into an array reference and returns it, if it isn't already
103       one.
104
105       _with_message($msg, $closure, @args)
106
107       This is the internal version of the general "Message" constraint. It
108       sets the current overriden message to $msg and executes the $closure
109       with @args as arguments.
110
111       _with_scope($scope_name, $constraint, @args)
112
113       Applies the $constraint to @args in a newly created scope named by
114       $scope_name.
115
116       _set_result($scope, $name, $result)
117
118       Stores the given $result unter the name $name in $scope.
119
120       _get_result($scope, $name)
121
122       Returns the result named $name from $scope.
123
124       _has_result($scope, $name)
125
126       Returns true only if such a result was registered already.
127

SEE ALSO

129       Declare::Constraints::Simple, Declare::Constraints::Simple::Library
130

AUTHOR

132       Robert 'phaylon' Sedlacek "<phaylon@dunkelheit.at>"
133
135       This module is free software, you can redistribute it and/or modify it
136       under the same terms as perl itself.
137
138
139
140perl v5.8.8                     De2c0l0a6r-e0:9:-C1o1nstraints::Simple::Library::Base(3)
Impressum