I can't find a clean way to put this into the metaclasses.
Also make sure to allow "." in type names.
cause very unhelpful errors when it tried to throw an error
before Moose was loaded. (Dave Rolsky)
+ * Moose::Util::TypeConstraints
+ - You could declare a name with subtype such as "Foo!Bar" that
+ would be allowed, but if you used it in a parameterized type
+ such as "ArrayRef[Foo!Bar]" it wouldn't work. We now do some
+ vetting on names created via the sugar functions, so that they
+ can only contain alphanumerics, ":", and ".".
+
0.65 Thu, January 22, 2008
* Moose and Moose::Meta::Method::Overridden
- If an overridden method called super(), and then the
. " and cannot be created again in "
. $pkg_defined_in )
if defined $type;
+
+ $name =~ /^[\w:\.]+$/
+ or die qq{$name contains invalid characters for a type name.}
+ . qq{Names can contain alphanumeric character, ":", and "."\n};
}
my %opts = (
use re "eval";
- my $valid_chars = qr{[\w:]};
+ my $valid_chars = qr{[\w:\.]};
my $type_atom = qr{ $valid_chars+ };
my $any;
=head2 Type Constraint Naming
+Type name declared via this module can only contain alphanumeric
+characters, colons (:), and periods (.).
+
Since the types created by this module are global, it is suggested
that you namespace your types just as you would namespace your
modules. So instead of creating a I<Color> type for your B<My::Graphics>
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+use Test::Exception;
+
+use Moose::Meta::TypeConstraint;
+use Moose::Util::TypeConstraints;
+
+
+TODO:
+{
+ local $TODO = 'type names are not validated in the TC metaclass';
+
+ throws_ok { Moose::Meta::TypeConstraint->new( name => 'Foo-Bar' ) }
+ qr/contains invalid characters/,
+ 'Type names cannot contain a dash';
+}
+
+lives_ok { Moose::Meta::TypeConstraint->new( name => 'Foo.Bar::Baz' ) }
+'Type names can contain periods and colons';
+
+throws_ok { subtype 'Foo-Baz' => as 'Item' }
+qr/contains invalid characters/,
+ 'Type names cannot contain a dash (via subtype sugar)';
+
+lives_ok { subtype 'Foo.Bar::Baz' => as 'Item' }
+'Type names can contain periods and colons (via subtype sugar)';
+
+is( Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[In-valid]'),
+ undef,
+ 'find_or_parse_type_constraint returns undef on an invalid name' );
+
+is( Moose::Util::TypeConstraints::find_or_parse_type_constraint('ArrayRef[Va.lid]'),
+ 'ArrayRef[Va.lid]',
+ 'find_or_parse_type_constraint returns name for valid name' );