has file => ( isa => 'ExistingFile', is => 'ro', required => 1, coerce => 1 );
####
You cannot coerce an attribute (file) unless its type (ExistingFile) has a coercion at /tmp/test.pl line 26
####
subtype 'ExistingFile' =>
as 'AFile' =>
where { say "In subtype where clause: $_[0]"; -f $_[0] },
message { "$_[0] does not exist" };
coerce 'ExistingFile' =>
from 'Str' =>
via { file($_) };
has file => ( isa => 'ExistingFile', is => 'ro', required => 1, coerce => 1 );
####
for my $ftype (qw/ AFile ExistingFile /) {
coerce $ftype =>
from 'Str' =>
via { file($_) };
}