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

HELPER FUNCTIONS

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

SEE ALSO

112       Declare::Constraints::Simple, Declare::Constraints::Simple::Library
113

AUTHOR

115       Robert 'phaylon' Sedlacek "<phaylon@dunkelheit.at>"
116
118       This module is free software, you can redistribute it and/or modify it
119       under the same terms as perl itself.
120
121
122
123perl v5.34.0                    De2c0l2a2r-e0:1:-C2o1nstraints::Simple::Library::Base(3)
Impressum