- or download this
use Types::Common::Numeric qw(PositiveInt);
has user_id => (
is => 'ro',
isa => PositiveInt,
);
- or download this
package MyApp::Types {
use Type::Library
-base,
...
...;
}
- or download this
declare User, as InstanceOf['MyApp::User'];
coerce User,
...
coerce UserId,
from User, via { $_->user_id };
- or download this
package MyApp::Types {
use Type::Library -base;
use Type::Utils (); # don't import any keywords
...
__PACKAGE__->make_immutable;
}
- or download this
# Imagine this is some code in a class...
#
...
isa => UserId->plus_coercions(Str, sub { ... }),
coerce => 1,
);