Excerpts from Dermot's message of Tue Jan 19 08:28:55 -0500 2010:
> 2010/1/19 Hans Dieter Pearcey <h...@pobox.com>:
> > subtype 'Whatever', as enum([ qw(foo bar baz) ]), ...;
                           ^^^^^^^^^^^^^^^^^^^^^^^^^

> So the answer is use 'as'.

Yes, that is *part* of the answer.  Look at the rest of the example.
 
> subtype 'IndexType'
>                => as enum( $_, qw[foo bar baz]),

This only works accidentally.

You are taking whatever is in $_ (maybe undef, maybe .. who knows) and
declaring an enum with that name.  This form of enum() happens to also return
that type name, but that's an implementation detail and not documented, so you
shouldn't depend on it.

If you're unlucky, some day $_ will contain "Int" and all your integer
attributes will suddenly start throwing error messages about how they don't
match "foo", "bar", or "baz".

Did you read the docs for enum() in Moose::Util::TypeConstraints?

hdp.

Reply via email to