GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  DECLARE::CONSTRAINTS::SIMPLE::LIBRARY::BASE (3)

.ds Aq ’

NAME

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

CONTENTS

SYNOPSIS



  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 Declare::Constraints::Simple::Library::Numericals;

  # with this we define a constraint to check a value
  # against a serial number regular expression
  constraint SomeSerial,
    sub {
      return sub {
        return _true if $_[0] =~ /\d{3}-\d{3}-\d{4}/;
        return _false(Not in SomeSerial format);
      };
    };

  1;



DESCRIPTION

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

METHODS

    install_into($target)

Installs the base classes and helper functions into the $target namespace. The %CONSTRAINT_GENERATORS package variable of that class will be used as storage for it’s constraints.

fetch_constraint_declarations()

Class method. Returns all constraints registered to the class.

    fetch_constraint_generator($name)

Class method. Returns the constraint generator code reference registered under $name. The call will raise a croak if the generator could not be found.

prepare_generator($constraint_name, CW$generator)

Class method. This wraps the $generator in a closure that provides stack and failure-collapsing decisions.

add_constraint_generator($name, CW$code)

Class method. The actual registration method, used by constraint.

HELPER FUNCTIONS

Note that some of the helper functions are prefixed with _. Although this means they are internal functions, it is ok to call them, as they have a fixed API. They are not distribution internal, but library internal, and only intended to be used from inside constraints.

constraint($name, CW$code)



  constraint Foo, sub { ... };



This registers a new constraint in the calling library. Note that constraints <B>have toB> return result objects. To do this, you can use the helper functions _result($bool, $msg, _true() and _false($msg).

_result($bool, CW$msg)

Returns a new result object. It’s validity flag will depend on the $bool argument. The $msg argument is the error message to use on failure.

    _false($msg)

Returns a non-valid result object, with it’s message set to $msg.

_true()

Returns a valid result object.

    _info($info)

Sets the current failure info to use in the stack info part.

    _apply_checks($value, \@constraints, [$info])

This applies all constraints in the \@constraints array reference to the passed $value. You can optionally specify an $info string to be used in the stack of the newly created non-valid results.

    _listify($value)

Puts $value into an array reference and returns it, if it isn’t already one.

_with_message($msg, CW$closure, CW@args)

This is the internal version of the general Message constraint. It sets the current overriden message to $msg and executes the $closure with @args as arguments.

_with_scope($scope_name, CW$constraint, CW@args)

Applies the $constraint to @args in a newly created scope named by $scope_name.

_set_result($scope, CW$name, CW$result)

Stores the given $result unter the name $name in $scope.

_get_result($scope, CW$name)

Returns the result named $name from $scope.

_has_result($scope, CW$name)

Returns true only if such a result was registered already.

SEE ALSO

Declare::Constraints::Simple, Declare::Constraints::Simple::Library

AUTHOR

Robert ’phaylon’ Sedlacek <phaylon@dunkelheit.at>

LICENSE AND COPYRIGHT

This module is free software, you can redistribute it and/or modify it under the same terms as perl itself.
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 DECLARE::CONSTRAINTS::SIMPLE::LIBRARY::BASE (3) 2006-09-11

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.