Checking in changes prior to tagging of version 0.68.
[gitmo/Mouse.git] / lib / Mouse / Meta / Class.pm
index 80f7af7..7ac4c83 100644 (file)
@@ -209,9 +209,13 @@ sub add_attribute {
 
     weaken( $attr->{associated_class} = $self );
 
-    $self->{attributes}{$attr->name} = $attr;
+    # install accessors first
     $attr->install_accessors();
 
+    # then register the attribute to the metaclass
+    $attr->{insertion_order} = keys %{ $self->{attributes} };
+    $self->{attributes}{$attr->name} = $attr;
+
     if(!$attr->{associated_methods} && ($attr->{is} || '') ne 'bare'){
         Carp::carp(qq{Attribute ($name) of class }.$self->name
             .qq{ has no associated methods (did you mean to provide an "is" argument?)});
@@ -219,38 +223,10 @@ sub add_attribute {
     return $attr;
 }
 
-sub compute_all_applicable_attributes { # DEPRECATED
-    Carp::cluck('compute_all_applicable_attributes() has been deprecated. Use get_all_attributes() instead');
-
-    return shift->get_all_attributes(@_)
-}
-
 sub linearized_isa;
 
 sub new_object;
-
-sub clone_object {
-    my $class  = shift;
-    my $object = shift;
-    my $args   = $object->Mouse::Object::BUILDARGS(@_);
-
-    (blessed($object) && $object->isa($class->name))
-        || $class->throw_error("You must pass an instance of the metaclass (" . $class->name . "), not ($object)");
-
-    my $cloned = bless { %$object }, ref $object;
-    $class->_initialize_object($cloned, $args);
-
-    return $cloned;
-}
-
-sub clone_instance { # DEPRECATED
-    my ($class, $instance, %params) = @_;
-
-    Carp::cluck('clone_instance() has been deprecated. Use clone_object() instead');
-
-    return $class->clone_object($instance, %params);
-}
-
+sub clone_object;
 
 sub immutable_options {
     my ( $self, @args ) = @_;
@@ -263,15 +239,12 @@ sub immutable_options {
     );
 }
 
-
 sub make_immutable {
     my $self = shift;
     my %args = $self->immutable_options(@_);
 
     $self->{is_immutable}++;
 
-    $self->{strict_constructor} = $args{strict_constructor};
-
     if ($args{inline_constructor}) {
         $self->add_method($args{constructor_name} =>
             Mouse::Util::load_class($self->constructor_class)
@@ -298,21 +271,27 @@ sub make_mutable {
 sub is_immutable;
 sub is_mutable   { !$_[0]->is_immutable }
 
-sub _install_modifier_pp{
+sub _install_modifier {
     my( $self, $type, $name, $code ) = @_;
     my $into = $self->name;
 
     my $original = $into->can($name)
-        or $self->throw_error("The method '$name' is not found in the inheritance hierarchy for class $into");
+        or $self->throw_error("The method '$name' was not found in the inheritance hierarchy for $into");
 
     my $modifier_table = $self->{modifiers}{$name};
 
     if(!$modifier_table){
-        my(@before, @after, @around, $cache, $modified);
+        my(@before, @after, $cache);
 
         $cache = $original;
 
-        $modified = sub {
+        my $around_only = ($type eq 'around');
+
+        my $modified = sub {
+            if($around_only) {
+                return $cache->(@_);
+            }
+
             for my $c (@before) { $c->(@_) }
 
             if(wantarray){ # list context
@@ -340,7 +319,8 @@ sub _install_modifier_pp{
 
             before   => \@before,
             after    => \@after,
-            around   => \@around,
+            around   => \my @around,
+            around_only => \$around_only,
 
             cache    => \$cache, # cache for around modifiers
         };
@@ -349,9 +329,11 @@ sub _install_modifier_pp{
     }
 
     if($type eq 'before'){
+        ${$modifier_table->{around_only}} = 0;
         unshift @{$modifier_table->{before}}, $code;
     }
     elsif($type eq 'after'){
+        ${$modifier_table->{around_only}} = 0;
         push @{$modifier_table->{after}}, $code;
     }
     else{ # around
@@ -364,41 +346,6 @@ sub _install_modifier_pp{
     return;
 }
 
-sub _install_modifier {
-    my ( $self, $type, $name, $code ) = @_;
-
-    # load Class::Method::Modifiers first
-    my $no_cmm_fast = do{
-        local $@;
-        eval q{ use Class::Method::Modifiers::Fast 0.041 () };
-        $@;
-    };
-
-    my $impl;
-    if($no_cmm_fast){
-        $impl = \&_install_modifier_pp;
-    }
-    else{
-        my $install_modifier = Class::Method::Modifiers::Fast->can('install_modifier');
-        $impl = sub {
-            my ( $self, $type, $name, $code ) = @_;
-            my $into = $self->name;
-            $install_modifier->($into, $type, $name, $code);
-
-            $self->add_method($name => Mouse::Util::get_code_ref($into, $name));
-            return;
-        };
-    }
-
-    # replace this method itself :)
-    {
-        no warnings 'redefine';
-        *_install_modifier = $impl;
-    }
-
-    $self->$impl( $type, $name, $code );
-}
-
 sub add_before_method_modifier {
     my ( $self, $name, $code ) = @_;
     $self->_install_modifier( 'before', $name, $code );
@@ -486,7 +433,12 @@ Mouse::Meta::Class - The Mouse class metaclass
 
 =head1 VERSION
 
-This document describes Mouse version 0.52
+This document describes Mouse version 0.68
+
+=head1 DESCRIPTION
+
+This class is a meta object protocol for Mouse classes,
+which is a subset of Moose::Meta:::Class.
 
 =head1 METHODS