Types with :: in their name now die on declaration
phaylon [Wed, 8 Aug 2007 18:37:18 +0000 (18:37 +0000)]
lib/MooseX/Types.pm
t/11_library-definition.t
t/lib/TestNamespaceSep.pm [new file with mode: 0644]

index 6bca30e..44b1996 100644 (file)
@@ -15,6 +15,7 @@ use MooseX::Types::Base             ();
 use MooseX::Types::Util             qw( filter_tags );
 use MooseX::Types::UndefinedType;
 use Sub::Install                    qw( install_sub );
+use Carp                            qw( croak );
 use Moose;
 
 use namespace::clean -except => [qw( meta )];
@@ -145,6 +146,9 @@ library which can export all types that come with Moose.
 You will have to define coercions for your types or your library won't
 export a L</to_$type> coercion helper for it.
 
+Note that you currently cannot define types containint C<::>, since 
+exporting would be a problem.
+
 =head1 LIBRARY USAGE
 
 You can import the L<"type helpers"|/"TYPE HANDLER FUNCTIONS"> of a
@@ -259,6 +263,10 @@ sub import {
         my ($tags, $declare) = filter_tags @orig_declare;
 
         for my $type (@$declare) {
+
+            croak "Cannot create a type containing '::' ($type) at the moment"
+                if $type =~ /::/;
+
             $callee->add_type($type);
             $callee->export_type_into(
                 $callee, $type, 
index c71fede..59d77b5 100644 (file)
@@ -12,7 +12,7 @@ my @tests = (
     [ 'IntArrayRef', 12, [12], {}, [17, 23], {} ],
 );
 
-plan tests => (@tests * 8) + 1;
+plan tests => (@tests * 8) + 3;
 
 # new array ref so we can safely shift from it
 for my $data (map { [@$_] } @tests) {
@@ -43,3 +43,7 @@ for my $data (map { [@$_] } @tests) {
 
 # coercion not available
 ok ! __PACKAGE__->can('to_TwentyThree'), "type without coercion doesn't have to_* helper";
+
+eval { require TestNamespaceSep };
+ok   $@,                q(trying to declare a type with '::' in it croaks);
+like $@, qr/Foo::Bar/,  q(error message contains type name);
diff --git a/t/lib/TestNamespaceSep.pm b/t/lib/TestNamespaceSep.pm
new file mode 100644 (file)
index 0000000..70a84f9
--- /dev/null
@@ -0,0 +1,7 @@
+package TestNamespaceSep;
+use warnings;
+use strict;
+
+use MooseX::Types -declare => [qw( Foo::Bar )];
+
+1;