NAME

SYNOPSIS

use Data::Predicate::ClosurePredicate;

#A closure which evaluates if a given object is defined or not
Data::Predicate::ClosurePredicate->new(closure => sub {
  my ($object) = @_;
  return (defined $object) ? 1 : 0;
}, description => 'Returns true if the given object is defined');

DESCRIPTION

A very simple abstraction from Data::Predicate which encapsulates the predicate logic in a closure given at construction time. This allows us to build very specific tests whilst keeping our class count down. It also allows for rapid prototyping of predicates & should speed become an issue means the code can be easily migrated into a custom version.

METHODS

new

Data::Predicate::ClosurePredicate->new(closure => sub {
  my ($object) = @_;
  return (defined $object) ? 1 : 0;
}, description => 'Returns true if the given object is defined');

Accepts 2 variables; closure & description. closure is a required argument where as description is not but recommended.

closure - required

Takes in a CodeRef and assumes it will return true or false depending on the outcome of evaluation of an object.

description

Allows you to tag a predicate with a description as when faced with multiple predicates all of which are ClosurePredicate instances it can be somewhat daunting.

Optional & defaults to unknown.

apply()

Returns the value from an invocation of the attribute closure with the incoming object.

AUTHOR

Andrew Yates

LICENCE

Copyright (c) 2010 - 2010 European Molecular Biology Laboratory.

Author: Andrew Yates (ayatesattheebi - remove the relevant sections accordingly)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright 
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 
   notice, this list of conditions and the following disclaimer in the 
   documentation and/or other materials provided with the distribution.
3. Neither the name of the Genome Research Ltd nor the names of its 
   contributors may be used to endorse or promote products derived from 
   this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.