Acme-Mitey-Cards
view release on metacpan or search on metacpan
lib/Acme/Mitey/Cards/Types.pm view on Meta::CPAN
sub check {
$_[0]{check}->( $_[1] );
}
sub get_message {
sprintf '%s did not pass type constraint "%s"',
defined( $_[1] ) ? $_[1] : 'Undef',
$_[0]{name};
}
sub validate {
$_[0]{check}->( $_[1] )
? undef
: $_[0]->get_message( $_[1] );
}
sub assert_valid {
$_[0]{check}->( $_[1] )
? 1
: Carp::croak( $_[0]->get_message( $_[1] ) );
}
lib/Acme/Mitey/Cards/Types.pm view on Meta::CPAN
To import all of these functions:
use Acme::Mitey::Cards::Types qw( :Value );
=head1 TYPE CONSTRAINT METHODS
For any type constraint B<Foo> the following methods are available:
Foo->check( $value ) # boolean
Foo->get_message( $value ) # error message, even if $value is ok
Foo->validate( $value ) # error message, or undef if ok
Foo->assert_valid( $value ) # returns true, dies if error
Foo->assert_return( $value ) # returns $value, or dies if error
Foo->to_TypeTiny # promotes the object to Type::Tiny
Objects overload stringification to return their name and overload
coderefification to call C<assert_return>.
The objects as-is can be used in L<Moo> or L<Mite> C<isa> options.
has myattr => (
( run in 0.487 second using v1.01-cache-2.11-cpan-4d50c553e7e )