Thanks. The above test script passes all tests with the following definitions. The redundancy is annoying, but it'll do until I get around to making/finding a proper trait/extension.
BEGIN { package Class; use strict; use warnings; use Moose; has val => ( is => 'rw', isa => 'Num', required => 1, ); use Moose::Util::TypeConstraints; coerce __PACKAGE__ => from 'Num' => via { __PACKAGE__->new(val => $_) }; subtype 'Maybe'.__PACKAGE__ => as 'Maybe['.__PACKAGE__.']'; coerce 'Maybe'.__PACKAGE__ => from 'Num' => via { __PACKAGE__->new(val => $_) }; } BEGIN { package Container; use strict; use warnings; use Moose; has always => ( is => 'rw', isa => 'Class', coerce => 1, default => sub { Class->new(val => 0) }, ); has maybe => ( is => 'rw', isa => 'MaybeClass', coerce => 1, default => undef, ); }
In reply to Re^4: Moose type question
by ikegami
in thread Moose type question
by Sue D. Nymme
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |