bump version and update changes.
[gitmo/Moose.git] / lib / Moose / Util / TypeConstraints.pm
index 15c1220..d50936b 100644 (file)
@@ -9,7 +9,7 @@ use List::MoreUtils qw( all );
 use Scalar::Util 'blessed';
 use Moose::Exporter;
 
-our $VERSION   = '0.59';
+our $VERSION   = '0.62_01';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -354,15 +354,15 @@ sub _create_type_constraint ($$$;$$) {
     my $parent = shift;
     my $check  = shift;
 
-    my ($message, $optimized);
+    my ( $message, $optimized );
     for (@_) {
         $message   = $_->{message}   if exists $_->{message};
         $optimized = $_->{optimized} if exists $_->{optimized};
     }
 
-    my $pkg_defined_in = scalar(caller(0));
+    my $pkg_defined_in = scalar( caller(0) );
 
-    if (defined $name) {
+    if ( defined $name ) {
         my $type = $REGISTRY->get_type_constraint($name);
 
         ( $type->_package_defined_in eq $pkg_defined_in )
@@ -373,41 +373,27 @@ sub _create_type_constraint ($$$;$$) {
                 . $pkg_defined_in )
             if defined $type;
     }
-    
-    ## Here are the basic options we will use to create the constraint.  These
-    ## may be altered depending on the parent type, etc.
-    
+
     my %opts = (
-        name => $name || '__ANON__',
+        name => $name,
         package_defined_in => $pkg_defined_in,
 
-        ($check     ? (constraint => $check)     : ()),
-        ($message   ? (message    => $message)   : ()),
-        ($optimized ? (optimized  => $optimized) : ()),
+        ( $check     ? ( constraint => $check )     : () ),
+        ( $message   ? ( message    => $message )   : () ),
+        ( $optimized ? ( optimized  => $optimized ) : () ),
     );
-    
-    ## If we have a parent we make sure to instantiate this new type constraint
-    ## as a subclass of the parents meta class.  We need to see if the $parent
-    ## is already a blessed TC or if we need to go make it based on it's name
-    
+
     my $constraint;
-    
-    if(
-        defined $parent
-        and $parent = blessed $parent ? $parent:find_or_parse_type_constraint($parent)
-    ) {
-        ## creating the child is a job we delegate to the parent, since each
-        ## parent may have local customization needs to influence it's child.
+    if ( defined $parent
+        and $parent
+        = blessed $parent ? $parent : find_or_parse_type_constraint($parent) )
+    {
         $constraint = $parent->create_child_type(%opts);
-    } else {
-        ## If for some reason the above couldn't create a type constraint, let's
-        ## make sure to create something.        
-        $constraint = Moose::Meta::TypeConstraint->new(%opts);    
+    }
+    else {
+        $constraint = Moose::Meta::TypeConstraint->new(%opts);
     }
 
-    ## Unless we have a request to make an anonynmous constraint, let's add it
-    ## to the $REGISTRY so that it gets cached for quicker lookups next time
-    
     $REGISTRY->add_type_constraint($constraint)
         if defined $name;
 
@@ -495,6 +481,27 @@ sub _install_type_coercions ($$) {
 # define some basic built-in types
 ## --------------------------------------------------------
 
+# By making these classes immutable before creating all the types we
+# below, we avoid repeatedly calling the slow MOP-based accessors.
+$_->make_immutable(
+    inline_constructor => 1,
+    constructor_name   => "_new",
+
+    # these are Class::MOP accessors, so they need inlining
+    inline_accessors => 1
+    ) for grep { $_->is_mutable }
+    map { $_->meta }
+    qw(
+    Moose::Meta::TypeConstraint
+    Moose::Meta::TypeConstraint::Union
+    Moose::Meta::TypeConstraint::Parameterized
+    Moose::Meta::TypeConstraint::Parameterizable
+    Moose::Meta::TypeConstraint::Class
+    Moose::Meta::TypeConstraint::Role
+    Moose::Meta::TypeConstraint::Enum
+    Moose::Meta::TypeConstraint::Registry
+);
+
 type 'Any'  => where { 1 }; # meta-type including all
 type 'Item' => where { 1 }; # base-type
 
@@ -973,7 +980,7 @@ C<find_or_create_does_type_constraint>.
 
 =item B<find_or_create_does_type_constraint ($type_name)>
 
-Attempts to parse the type name using L<find_or_parse_type_constraint> and if
+Attempts to parse the type name using C<find_or_parse_type_constraint> and if
 no appropriate constraint is found will create a new anonymous one.
 
 The C<isa> variant will use C<create_class_type_constraint> and the C<does>