My experience with Moose is nil, but how about something like that:
my %enum = ( A => 0, B => 1, C => 2);
subtype 'MyEnum',
as 'Str',
where { exists $enum{$_} },
message { "Wrong Enum name: $_" };
And then:
coerce 'MyEnum',
from 'Int',
via { $enum{$_} };
Shmuel.
On Wed, Apr 4, 2012 at 3:27 PM, Dov Levenglick <[email protected]>wrote:
> Hi,
> I want to declare a 3 value'd enum equivalent - i.e. (mixing C and perl):
>
> package My::Enum
> use Moose;
>
> typedef enum {A, B, C} enum_t; // knowledge in C - how do I
> port this concept to Perl?
> has 'b' => (isa => 'enum_t', is => 'rw');
>
> 1;
>
>
> How would one go about doing that
>
>
> Best Regards,
> Dov Levenglick
> _______________________________________________
> Perl mailing list
> [email protected]
> http://mail.perl.org.il/mailman/listinfo/perl
>
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl