On Fri, Mar 21, 2014 at 12:07:48PM +0000, Richard Harris wrote:
subtype 'A', as 'Str', where { $_ eq 'foo' };
subtype 'B', as 'Str', where { $_ =~ /some regex/ };
subtype 'C', as 'Str', where { $_ =~ /different regex/ };
subtype 'Foo', as 'A|B|C', message { 'Invalid Foo' };
has foo => (is => 'rw', isa => 'Foo', required => 1, coerce => 1);
The warning is: "You can't coerce an attribute (foo) unless its type
(Foo) has a coercion",
Am I using the API wrong here? If so, what would be a better way to do
this? Is a workaround available or is there a bug?
subtype 'A', as 'Str', where { $_ eq 'foo' };
subtype 'B', as 'Str', where { $_ =~ /some regex/ };
subtype 'C', as 'Str', where { $_ =~ /different regex/ };
subtype 'Foo', as 'A|B|C', message { 'Invalid Foo' };
has foo => (is => 'rw', isa => 'Foo', required => 1, coerce => 1);
The warning is: "You can't coerce an attribute (foo) unless its type
(Foo) has a coercion",
Am I using the API wrong here? If so, what would be a better way to do
this? Is a workaround available or is there a bug?
coerce => 1, but the type of that attribute (Foo) has no coercions
declared. So, either remove the 'coerce => 1' bit, or add something to your
Foo type explaining how to coerce it from some other type.