— |
use lib qw( ./lib ./t/lib ../inc ./inc ) ; {
use Type::Utils qw( declare as where inline_as coerce from ) ;
::isa_ok(
Int,
'Moose::Meta::TypeConstraint' ,
'Int' ,
);
::isa_ok(
Str,
'Moose::Meta::TypeConstraint' ,
'Str' ,
);
has name => (
is => "ro" ,
isa => Str,
);
my $PositiveInt = declare
as Int,
where { $_ > 0 },
inline_as { "$_ =~ /^0-9]\$/ and $_ > 0" };
coerce $PositiveInt , from Int, q{ abs $_ } ;
::isa_ok(
$PositiveInt ,
'Type::Tiny' ,
'$PositiveInt' ,
);
::isa_ok(
$PositiveInt ->parent,
'Type::Tiny' ,
'$PositiveInt->parent' ,
);
has age => (
is => "ro" ,
isa => $PositiveInt ,
coerce => 1,
writer => "_set_age" ,
);
sub get_older {
my $self = shift ;
my ( $years ) = @_ ;
$PositiveInt ->assert_valid( $years );
$self ->_set_age( $self ->age + $years );
}
}
done_testing;
|