Grokbase Groups Perl moose March 2014
FAQ

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?
The warning seems pretty clear to me -- you've declared an attribute with
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.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 3 | next ›
Discussion Overview
groupmoose @
categoriesperl
postedMar 21, '14 at 12:09p
activeMay 15, '14 at 11:55a
posts3
users3
websiteiinteractive.com...

People

Translate

site design / logo © 2021 Grokbase