Document how to pass new attribute values at instance-role application time
[gitmo/Moose.git] / lib / Moose / Meta / TypeConstraint / Enum.pm
index 4dfc8ce..3ef7234 100644 (file)
@@ -11,10 +11,12 @@ use base 'Moose::Meta::TypeConstraint';
 
 __PACKAGE__->meta->add_attribute('values' => (
     accessor => 'values',
+    Class::MOP::_definition_context(),
 ));
 
 __PACKAGE__->meta->add_attribute('_inline_var_name' => (
     accessor => '_inline_var_name',
+    Class::MOP::_definition_context(),
 ));
 
 my $inliner = sub {
@@ -26,8 +28,7 @@ my $inliner = sub {
              . '&& $' . $self->_inline_var_name . '{' . $val . '}';
 };
 
-# a quadrillion enums ought to be enough for any app
-my $var_suffix = '000000000000000000';
+my $var_suffix = 0;
 
 sub new {
     my ( $class, %args ) = @_;
@@ -35,9 +36,9 @@ sub new {
     $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Str');
     $args{inlined} = $inliner;
 
-    if ( scalar @{ $args{values} } < 2 ) {
+    if ( scalar @{ $args{values} } < 1 ) {
         require Moose;
-        Moose->throw_error("You must have at least two values to enumerate through");
+        Moose->throw_error("You must have at least one value to enumerate through");
     }
 
     for (@{ $args{values} }) {
@@ -58,7 +59,7 @@ sub new {
     $args{_inline_var_name} = $var_name;
     $args{inline_environment} = { '%' . $var_name => \%values };
 
-    my $self = $class->_new(\%args);
+    my $self = $class->SUPER::new(\%args);
 
     $self->compile_type_constraint()
         unless $self->_has_compiled_type_constraint;