bump version to 0.93
[gitmo/Class-MOP.git] / lib / Class / MOP / Class.pm
index c2679a7..de32b1a 100644 (file)
@@ -14,7 +14,7 @@ use Scalar::Util 'blessed', 'reftype', 'weaken';
 use Sub::Name    'subname';
 use Devel::GlobalDestruction 'in_global_destruction';
 
-our $VERSION   = '0.92';
+our $VERSION   = '0.93';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -69,7 +69,7 @@ sub _construct_class_instance {
     # get the name of the class appropriately
     $class = (ref($class)
                     ? ($class->is_immutable
-                        ? $class->get_mutable_metaclass_name()
+                        ? $class->_get_mutable_metaclass_name()
                         : ref($class))
                     : $class);
 
@@ -120,6 +120,7 @@ sub _new {
         # should not actually have a value associated
         # with the slot.
         'namespace' => \undef,
+        'methods'   => {},
 
         # inherited from Class::MOP::Module
         'version'   => \undef,
@@ -128,7 +129,6 @@ sub _new {
         # defined in Class::MOP::Class
         'superclasses' => \undef,
 
-        'methods'    => {},
         'attributes' => {},
         'attribute_metaclass' =>
             ( $options->{'attribute_metaclass'} || 'Class::MOP::Attribute' ),
@@ -183,7 +183,7 @@ sub _check_metaclass_compatibility {
         # get the name of the class appropriately
         my $super_meta_type
             = $super_meta->is_immutable
-            ? $super_meta->get_mutable_metaclass_name()
+            ? $super_meta->_get_mutable_metaclass_name()
             : ref($super_meta);
 
         ($self->isa($super_meta_type))
@@ -650,7 +650,15 @@ sub find_method_by_name {
 
 sub get_all_methods {
     my $self = shift;
-    my %methods = map { %{ $self->initialize($_)->get_method_map } } reverse $self->linearized_isa;
+
+    my %methods;
+    for my $class ( reverse $self->linearized_isa ) {
+        my $meta = $self->initialize($class);
+
+        $methods{$_} = $meta->get_method($_)
+            for $meta->get_method_list;
+    }
+
     return values %methods;
 }
 
@@ -863,12 +871,9 @@ sub is_pristine {
     return if $self->get_attribute_list;
 
     # or any non-declared methods
-    if ( my @methods = values %{ $self->get_method_map } ) {
-        my $metaclass = $self->method_metaclass;
-        foreach my $method ( @methods ) {
-            return if $method->isa("Class::MOP::Method::Generated");
-            # FIXME do we need to enforce this too? return unless $method->isa($metaclass);
-        }
+    for my $method ( map { $self->get_method($_) } $self->get_method_list ) {
+        return if $method->isa("Class::MOP::Method::Generated");
+        # FIXME do we need to enforce this too? return unless $method->isa( $self->method_metaclass );
     }
 
     return 1;
@@ -879,6 +884,8 @@ sub is_pristine {
 sub is_mutable   { 1 }
 sub is_immutable { 0 }
 
+sub immutable_options { %{ $_[0]{__immutable}{options} || {} } }
+
 sub _immutable_options {
     my ( $self, @args ) = @_;
 
@@ -965,7 +972,7 @@ sub _immutable_metaclass {
     # example of where this matters).
     my $meta_name
         = $meta->is_immutable
-        ? $meta->get_mutable_metaclass_name
+        ? $meta->_get_mutable_metaclass_name
         : ref $meta;
 
     my $immutable_meta = $meta_name->create(
@@ -1028,7 +1035,7 @@ sub _install_inlined_code {
 sub _rebless_as_mutable {
     my $self = shift;
 
-    bless $self, $self->get_mutable_metaclass_name;
+    bless $self, $self->_get_mutable_metaclass_name;
 
     return $self;
 }
@@ -1508,11 +1515,10 @@ Making a class immutable lets us optimize the class by inlining some
 methods, and also allows us to optimize some methods on the metaclass
 object itself.
 
-After immutabilization, the metaclass object will cache most
-informational methods such as C<get_method_map> and
-C<get_all_attributes>. Methods which would alter the class, such as
-C<add_attribute>, C<add_method>, and so on will throw an error on an
-immutable metaclass object.
+After immutabilization, the metaclass object will cache most informational
+methods that returns information about methods or attributes.. Methods which
+would alter the class, such as C<add_attribute>, C<add_method>, and so on will
+throw an error on an immutable metaclass object.
 
 The immutabilization system in L<Moose> takes much greater advantage
 of the inlining features than Class::MOP itself does.
@@ -1577,6 +1583,13 @@ replaced when inlining a destructor. This defaults to false.
 
 =back
 
+=item B<< $metaclass->immutable_options >>
+
+Returns a hash of the options used when making the class immutable, including
+both defaults and anything supplied by the user in the call to C<<
+$metaclass->make_immutable >>. This is useful if you need to temporarily make
+a class mutable and then restore immutability as it was before.
+
 =item B<< $metaclass->make_mutable >>
 
 Calling this method reverse the immutabilization transformation.