I can do this:
package Foo;
use Moose;
has 'time' => (
is => 'rw',
isa => 'DateTime'
);
package main;
use DateTime;
my $a = Foo->new(time => DateTime->now);
But not this:
package Foo;
use Moose;
has 'time' => (
is => 'rw',
isa => 'DateTime | Str'
);
package main;
use DateTime;
my $a = Foo->new(time => DateTime->now);
As it raises an exception:
Could not locate type constraint (DateTime) for the union
at /opt/xt/xt-perl/lib/site_perl/5.8.8/Moose/Util/TypeConstraints.pm line 89
Without defining a SubType first. Why is this, and is there a way around it (apart from defining a subtype that checks 'isa')?