Data-Validation
view release on metacpan or search on metacpan
lib/Data/Validation.pm view on Meta::CPAN
use Data::Validation::Constants qw( EXCEPTION_CLASS FALSE HASH NUL SPC );
use Data::Validation::Constraints;
use Data::Validation::Filters;
use Data::Validation::Utils qw( throw );
use List::Util qw( first );
use Try::Tiny;
use Unexpected::Functions qw( FieldComparison ValidationErrors );
use Unexpected::Types qw( HashRef NonZeroPositiveInt );
use Moo;
has 'constraints' => is => 'ro', isa => HashRef, default => sub { {} };
has 'fields' => is => 'ro', isa => HashRef, default => sub { {} };
has 'filters' => is => 'ro', isa => HashRef, default => sub { {} };
has 'level' => is => 'ro', isa => NonZeroPositiveInt, default => 1;
# Private functions
my $_comparisons = sub {
return { 'eq' => sub { $_[ 0 ] eq $_[ 1 ] },
'==' => sub { $_[ 0 ] == $_[ 1 ] },
'ne' => sub { $_[ 0 ] ne $_[ 1 ] },
'!=' => sub { $_[ 0 ] != $_[ 1 ] },
'>' => sub { $_[ 0 ] > $_[ 1 ] },
lib/Data/Validation/Constraints.pm view on Meta::CPAN
use Data::Validation::Constants qw( EXCEPTION_CLASS FALSE HASH TRUE );
use Data::Validation::Utils qw( ensure_class_loaded load_class throw );
use List::Util qw( any );
use Scalar::Util qw( looks_like_number );
use Try::Tiny;
use Unexpected::Functions qw( KnownType );
use Unexpected::Types qw( Any ArrayRef Bool Int Object Str Undef );
use Moo;
# Public attributes
has 'allowed' => is => 'ro', iss => ArrayRef, builder => sub { [] };
has 'max_length' => is => 'ro', isa => Int;
has 'max_value' => is => 'ro', isa => Int;
has 'method' => is => 'ro', isa => Str, required => TRUE;
has 'min_length' => is => 'ro', isa => Int;
has 'min_value' => is => 'ro', isa => Int;
has 'pattern' => is => 'ro', isa => Str;
has 'required' => is => 'ro', isa => Bool, default => FALSE;
has 'type' => is => 'ro', isa => Str | Undef;
has 'type_libraries' => is => 'ro', isa => ArrayRef[Str],
builder => sub { [ 'Unexpected::Types' ] };
has 'type_registry' => is => 'lazy', isa => Object, builder => sub {
my $self = shift; ensure_class_loaded 'Type::Registry';
my $reg = Type::Registry->for_me;
$reg->add_types( $_ ) for (@{ $self->type_libraries });
return $reg;
};
( run in 0.757 second using v1.01-cache-2.11-cpan-5f2e87ce722 )