Data-Type
view release on metacpan or search on metacpan
lib/Data/Type/Facet.pm view on Meta::CPAN
throw Data::Type::Facet::Exception( text => '$_[0] does not exist in array' );
};
multimethod _exists => ( 'ARRAY', 'HASH' ) => sub : method
{
_exists( $_, $_[1] ) for @{ $_[0] };
};
multimethod _exists => ( 'ARRAY', 'ARRAY' ) => sub : method
{
_exists( $_, $_[1] ) for @{ $_[0] };
};
sub test : method
{
my $this = shift;
_exists( $Data::Type::value, @$this );
}
sub info : method
{
my $this = shift;
if( ref( $this->[0] ) eq 'HASH' )
{
return sprintf 'element of hash keys (%s)', join( ', ', keys %{ $this->[0] } );
}
return sprintf 'element of array (%s)', join( ', ', @{$this->[0]} );
}
package Data::Type::Facet::mod10check;
our @ISA = qw(Data::Type::Facet::Interface);
our $VERSION = '0.01.01';
sub desc : method { 'passes the mod10 LUHN algorithm check' }
# could have used Algorithm::LUHN
sub test : method
{
my $this = shift;
eval "use Business::CreditCard;";
die $@ if $@;
# We use Business::CreditCard's mod10 luhn
throw Data::Type::Facet::Exception( text => "mod10check failed" ) unless validate( $Data::Type::value );
}
sub info : method
{
my $this = shift;
return 'LUHN formula (mod 10) for validation of creditcards';
}
# To be implemented and not yet really usefull yet.
#
package Data::Type::Facet::file;
our @ISA = qw(Data::Type::Facet::Interface);
our $VERSION = '0.01.01';
sub desc : method { 'whether file is existent' }
sub usage : method { '( FILENAME )' }
sub info : method { 'tests characteristics of file' }
sub test : method
{
my $this = shift;
throw Data::Type::Facet::Exception( text => 'undefined value' ) unless defined $Data::Type::value;
throw Data::Type::Facet::Exception(
text => 'supplied filename does not exist',
value => $Data::Type::value,
type => __PACKAGE__
) unless -e $Data::Type::value;
}
1;
__END__
=head1 NAME
Data::Type::Facet - a subelement of a type
=head1 SYNOPSIS
package Data::Type::Object::std_real;
...
sub _test
{
my $this = shift;
Data::Type::ok( 1, Data::Type::Facet::match( 'std/real' ) );
}
=head1 DESCRIPTION
Facets are bric's for L<Data::Type::Object>'s. They are partially almost trivial (more or less), but have some advantages. They are modularising the testing procedure of any datatype (and therefore giving the magic to the L<Data::Type/summary()> func...
=head1 EXCEPTIONS
( run in 0.423 second using v1.01-cache-2.11-cpan-71847e10f99 )