import no longer necessary
[gitmo/Moose.git] / lib / Moose / Util / TypeConstraints.pm
index 9e3a832..51cfd79 100644 (file)
@@ -8,7 +8,7 @@ use Carp         'confess';
 use Scalar::Util 'blessed';
 use Sub::Exporter;
 
-our $VERSION   = '0.24';
+our $VERSION   = '0.50';
 our $AUTHORITY = 'cpan:STEVAN';
 
 ## --------------------------------------------------------
@@ -108,7 +108,7 @@ sub export_type_constraints_as_functions {
     no strict 'refs';
     foreach my $constraint (keys %{$REGISTRY->type_constraints}) {
         my $tc = $REGISTRY->get_type_constraint($constraint)->_compiled_type_constraint;
-        *{"${pkg}::${constraint}"} = sub { $tc->($_[0]) ? 1 : undef };
+        *{"${pkg}::${constraint}"} = sub { $tc->($_[0]) ? 1 : undef }; # the undef is for compat
     }
 }
 
@@ -455,6 +455,8 @@ sub _install_type_coercions ($$) {
     my $valid_chars = qr{[\w:]};
     my $type_atom   = qr{ $valid_chars+ };
 
+    my $any;
+
     my $type                = qr{  $valid_chars+  (?: \[  (??{$any})  \] )? }x;
     my $type_capture_parts  = qr{ ($valid_chars+) (?: \[ ((??{$any})) \] )? }x;
     my $type_with_parameter = qr{  $valid_chars+      \[  (??{$any})  \]    }x;
@@ -462,18 +464,21 @@ sub _install_type_coercions ($$) {
     my $op_union = qr{ \s* \| \s* }x;
     my $union    = qr{ $type (?: $op_union $type )+ }x;
 
-    our $any = qr{ $type | $union }x;
+    $any = qr{ $type | $union }x;
 
     sub _parse_parameterized_type_constraint {
+        { no warnings 'void'; $any; } # force capture of interpolated lexical
         $_[0] =~ m{ $type_capture_parts }x;
         return ($1, $2);
     }
 
     sub _detect_parameterized_type_constraint {
+        { no warnings 'void'; $any; } # force capture of interpolated lexical
         $_[0] =~ m{ ^ $type_with_parameter $ }x;
     }
 
     sub _parse_type_constraint_union {
+        { no warnings 'void'; $any; } # force capture of interpolated lexical
         my $given = shift;
         my @rv;
         while ( $given =~ m{ \G (?: $op_union )? ($type) }gcx ) {
@@ -489,6 +494,7 @@ sub _install_type_coercions ($$) {
     }
 
     sub _detect_type_constraint_union {
+        { no warnings 'void'; $any; } # force capture of interpolated lexical
         $_[0] =~ m{^ $type $op_union $type ( $op_union .* )? $}x;
     }
 }
@@ -558,38 +564,12 @@ subtype 'Role'
     => optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::Role;
 
 my $_class_name_checker = sub {
-    return if ref($_[0]);
-    return unless defined($_[0]) && length($_[0]);
-
-    # walk the symbol table tree to avoid autovififying
-    # \*{${main::}{"Foo::"}} == \*main::Foo::
-
-    my $pack = \*::;
-    foreach my $part (split('::', $_[0])) {
-        return unless exists ${$$pack}{"${part}::"};
-        $pack = \*{${$$pack}{"${part}::"}};
-    }
-
-    # check for $VERSION or @ISA
-    return 1 if exists ${$$pack}{VERSION}
-             && defined *{${$$pack}{VERSION}}{SCALAR};
-    return 1 if exists ${$$pack}{ISA}
-             && defined *{${$$pack}{ISA}}{ARRAY};
-
-    # check for any method
-    foreach ( keys %{$$pack} ) {
-        next if substr($_, -2, 2) eq '::';
-        return 1 if defined *{${$$pack}{$_}}{CODE};
-    }
-
-    # fail
-    return;
 };
 
 subtype 'ClassName'
     => as 'Str'
-    => $_class_name_checker # where ...
-    => { optimize => $_class_name_checker };
+    => where { Class::MOP::is_class_loaded($_) }
+    => optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::ClassName;
 
 ## --------------------------------------------------------
 # parameterizable types ...