OS:Ubuntu 18
Perl:Active State Perl ,V5.26.1
My Code====>
BEGIN{
package User {
use Class::Tiny qw(name age sex);
};
$INC{"User.pm"} = __FILE__;
}
BEGIN{
package UserType {
use Type::Library -base, -declare => qw(UserWrapper Age);
use Types::Standard -types;
use Type::Utils qw(class_type declare coerce as where message from via);
use Type::Tiny;
class_type UserWrapper, { class => "User" };
declare Age, as Int,
where { $_ >= 10 and $_ < 20 },
message {
"abc";
};
coerce UserWrapper,
from Age, via {"User"->new(age => $_)};
};
$INC{"UserType.pm"} = __FILE__;
}
package MyType {
use Moose;
use User;
use UserType qw(UserWrapper Age);
has 'User' => (is => 'rw', isa => UserWrapper, coerce => 1);
}
my $j = MyType->new(User => 4)
The Output===>
Attribute (User) does not pass the type constraint because: Value "4" did not pass type constraint "UserWrapper" (not isa User) at /opt/scientific/libs/perl5/site/lib/Moose/Object.pm line 24
Moose::Object::new('MyType', 'User', 4) called at /root/PycharmProjects/untitled/info.pl line 107
In other words, the "message" prompt for my custom type "Age" does not take effect. Is this a problem with my use? Still not configured. Please advise, thank you