.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Declare::Constraints::Simple::Library::Base 3pm" .TH Declare::Constraints::Simple::Library::Base 3pm "2021-01-09" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Declare::Constraints::Simple::Library::Base \- Library Base Class .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& package My::Constraint::Library; \& use warnings; \& use strict; \& \& # this installs the base class and helper functions \& use Declare::Constraints::Simple\-Library; \& \& # we can also automagically provide other libraries \& # to the importer \& use base \*(AqDeclare::Constraints::Simple::Library::Numericals\*(Aq; \& \& # with this we define a constraint to check a value \& # against a serial number regular expression \& constraint \*(AqSomeSerial\*(Aq, \& sub { \& return sub { \& return _true if $_[0] =~ /\ed{3}\-\ed{3}\-\ed{4}/; \& return _false(\*(AqNot in SomeSerial format\*(Aq); \& }; \& }; \& \& 1; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This base class contains the common library functionalities. This includes helper functions and install mechanisms. .SH "METHODS" .IX Header "METHODS" .SS "install_into($target)" .IX Subsection "install_into($target)" Installs the base classes and helper functions into the \f(CW$target\fR namespace. The \f(CW%CONSTRAINT_GENERATORS\fR package variable of that class will be used as storage for it's constraints. .SS "\fBfetch_constraint_declarations()\fP" .IX Subsection "fetch_constraint_declarations()" Class method. Returns all constraints registered to the class. .SS "fetch_constraint_generator($name)" .IX Subsection "fetch_constraint_generator($name)" Class method. Returns the constraint generator code reference registered under \f(CW$name\fR. The call will raise a \f(CW\*(C`croak\*(C'\fR if the generator could not be found. .ie n .SS "prepare_generator($constraint_name, $generator)" .el .SS "prepare_generator($constraint_name, \f(CW$generator\fP)" .IX Subsection "prepare_generator($constraint_name, $generator)" Class method. This wraps the \f(CW$generator\fR in a closure that provides stack and failure-collapsing decisions. .ie n .SS "add_constraint_generator($name, $code)" .el .SS "add_constraint_generator($name, \f(CW$code\fP)" .IX Subsection "add_constraint_generator($name, $code)" Class method. The actual registration method, used by \f(CW\*(C`constraint\*(C'\fR. .SH "HELPER FUNCTIONS" .IX Header "HELPER FUNCTIONS" Note that some of the helper functions are prefixed with \f(CW\*(C`_\*(C'\fR. Although this means they are internal functions, it is ok to call them, as they have a fixed \s-1API.\s0 They are not distribution internal, but library internal, and only intended to be used from inside constraints. .ie n .SS "constraint($name, $code)" .el .SS "constraint($name, \f(CW$code\fP)" .IX Subsection "constraint($name, $code)" .Vb 1 \& constraint \*(AqFoo\*(Aq, sub { ... }; .Ve .PP This registers a new constraint in the calling library. Note that constraints \fBhave to\fR return result objects. To do this, you can use the helper functions \*(L"_result($bool, \f(CW$msg\fR\*(R", \fB_true()\fR and _false($msg). .ie n .SS "_result($bool, $msg)" .el .SS "_result($bool, \f(CW$msg\fP)" .IX Subsection "_result($bool, $msg)" Returns a new result object. It's validity flag will depend on the \&\f(CW$bool\fR argument. The \f(CW$msg\fR argument is the error message to use on failure. .SS "_false($msg)" .IX Subsection "_false($msg)" Returns a non-valid result object, with it's message set to \f(CW$msg\fR. .SS "\fB_true()\fP" .IX Subsection "_true()" Returns a valid result object. .SS "_info($info)" .IX Subsection "_info($info)" Sets the current failure info to use in the stack info part. .SS "_apply_checks($value, \e@constraints, [$info])" .IX Subsection "_apply_checks($value, @constraints, [$info])" This applies all constraints in the \f(CW\*(C`\e@constraints\*(C'\fR array reference to the passed \f(CW$value\fR. You can optionally specify an \f(CW$info\fR string to be used in the stack of the newly created non-valid results. .SS "_listify($value)" .IX Subsection "_listify($value)" Puts \f(CW$value\fR into an array reference and returns it, if it isn't already one. .ie n .SS "_with_message($msg, $closure, @args)" .el .SS "_with_message($msg, \f(CW$closure\fP, \f(CW@args\fP)" .IX Subsection "_with_message($msg, $closure, @args)" This is the internal version of the general \f(CW\*(C`Message\*(C'\fR constraint. It sets the current overridden message to \f(CW$msg\fR and executes the \&\f(CW$closure\fR with \f(CW@args\fR as arguments. .ie n .SS "_with_scope($scope_name, $constraint, @args)" .el .SS "_with_scope($scope_name, \f(CW$constraint\fP, \f(CW@args\fP)" .IX Subsection "_with_scope($scope_name, $constraint, @args)" Applies the \f(CW$constraint\fR to \f(CW@args\fR in a newly created scope named by \f(CW$scope_name\fR. .ie n .SS "_set_result($scope, $name, $result)" .el .SS "_set_result($scope, \f(CW$name\fP, \f(CW$result\fP)" .IX Subsection "_set_result($scope, $name, $result)" Stores the given \f(CW$result\fR unter the name \f(CW$name\fR in \f(CW$scope\fR. .ie n .SS "_get_result($scope, $name)" .el .SS "_get_result($scope, \f(CW$name\fP)" .IX Subsection "_get_result($scope, $name)" Returns the result named \f(CW$name\fR from \f(CW$scope\fR. .ie n .SS "_has_result($scope, $name)" .el .SS "_has_result($scope, \f(CW$name\fP)" .IX Subsection "_has_result($scope, $name)" Returns true only if such a result was registered already. .SH "SEE ALSO" .IX Header "SEE ALSO" Declare::Constraints::Simple, Declare::Constraints::Simple::Library .SH "AUTHOR" .IX Header "AUTHOR" Robert 'phaylon' Sedlacek \f(CW\*(C`\*(C'\fR .SH "LICENSE AND COPYRIGHT" .IX Header "LICENSE AND COPYRIGHT" This module is free software, you can redistribute it and/or modify it under the same terms as perl itself.