2010/1/19 Hans Dieter Pearcey <h...@pobox.com>:
> Excerpts from Dermot's message of Tue Jan 19 07:34:35 -0500 2010:
>> subtype 'IndexType'
>>                 => as 'Str',
>>                 => enum( $_, qw[foo bar baz]);
>
> enum() is already a Str, and in any case the syntax you made up doesn't
> correspond to anything.


Ouch! I tried to make an attempt at merging the examples from
Moose/Util/TypeConstraints.pm. Sorry if I was off target.

> You want the anonymous enum syntax.  Just subtype it:
>
>  subtype 'Whatever', as enum([ qw(foo bar baz) ]), ...;


So the answer is use 'as'.

subtype 'IndexType'
               => as enum( $_, qw[foo bar baz]),
               => message { "index_type ($_) must be one of ". join ',
', qw(foo bar baz)},

has 'index_type'    => (
                isa         => 'IndexType',
                is          => 'ro',
                required    => 1,
    );

Thank you, that works and I'm getting my message.
Dp.

Reply via email to