foo
[gitmo/Class-MOP.git] / lib / Class / MOP / Class.pm
index 0a16c25..f5e9f8d 100644 (file)
@@ -4,6 +4,7 @@ package Class::MOP::Class;
 use strict;
 use warnings;
 
+use Class::MOP::Immutable;
 use Class::MOP::Instance;
 use Class::MOP::Method::Wrapped;
 
@@ -729,14 +730,17 @@ sub is_mutable   { 1 }
 sub is_immutable { 0 }
 
 {
-    use Class::MOP::Immutable;
-    
-    my $IMMUTABLE_META;
-
+    # NOTE:
+    # the immutable version of a 
+    # particular metaclass is 
+    # really class-level data so 
+    # we don't want to regenerate 
+    # it any more than we need to
+    my $IMMUTABLE_METACLASS;
     sub make_immutable {
         my ($self) = @_;
         
-        $IMMUTABLE_META ||= Class::MOP::Immutable->new($self->meta, {
+        $IMMUTABLE_METACLASS ||= Class::MOP::Immutable->new($self, {
             read_only   => [qw/superclasses/],
             cannot_call => [qw/
                 add_method
@@ -753,9 +757,9 @@ sub is_immutable { 0 }
                 get_meta_instance                 => 'SCALAR',     
                 get_method_map                    => 'SCALAR',     
             }
-        })->create_immutable_metaclass;
-                
-        $IMMUTABLE_META->make_metaclass_immutable(@_);
+        });   
+        
+        $IMMUTABLE_METACLASS->make_metaclass_immutable(@_)     
     }
 }
 
@@ -1224,13 +1228,13 @@ their own. See L<Class::MOP::Attribute> for more details.
 
 =item B<get_attribute_map>
 
-=item B<add_attribute ($attribute_name, $attribute_meta_object)>
+=item B<add_attribute ($attribute_meta_object | $attribute_name, %attribute_spec)>
 
-This stores a C<$attribute_meta_object> in the B<Class::MOP::Class> 
-instance associated with the given class, and associates it with 
-the C<$attribute_name>. Unlike methods, attributes within the MOP 
-are stored as meta-information only. They will be used later to 
-construct instances from (see C<construct_instance> above).
+This stores the C<$attribute_meta_object> (or creates one from the
+C<$attribute_name> and C<%attribute_spec>) in the B<Class::MOP::Class> 
+instance associated with the given class. Unlike methods, attributes 
+within the MOP are stored as meta-information only. They will be used 
+later to construct instances from (see C<construct_instance> above).
 More details about the attribute meta-objects can be found in the 
 L<Class::MOP::Attribute> or the L<Class::MOP/The Attribute protocol>
 section.