X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=4aa1baaf756e4533a317270cc215c2d5f1233a09;hb=12f4a95a9552fd877d5efca81da5b60bc132d4c8;hp=f37da15fd892b3340853949a97546b2357eb7201;hpb=6e1e5b31f9ff0a46de1d7e396840da18c385962d;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index f37da15..4aa1baa 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -129,7 +129,7 @@ sub _collect_roles { } my %seen; - return sort grep { !$seen{$_}++ } + return sort grep { !$seen{$_}++ } ## no critic (map{ $_->name } map{ $_->meta->calculate_all_roles } @self_anon_supers), (map{ $_->name } map{ $_->meta->calculate_all_roles } @other_anon_supers), ; @@ -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) @@ -303,7 +276,7 @@ sub _install_modifier_pp{ 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}; @@ -367,10 +340,10 @@ sub _install_modifier_pp{ sub _install_modifier { my ( $self, $type, $name, $code ) = @_; - # load Class::Method::Modifiers first + # load Data::Util first my $no_cmm_fast = do{ local $@; - eval q{ use Class::Method::Modifiers::Fast 0.041 () }; + eval q{ use Data::Util 0.55 () }; $@; }; @@ -379,17 +352,37 @@ sub _install_modifier { $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)); + my $method = Mouse::Util::get_code_ref( $into, $name ); + + if ( !$method || !Data::Util::subroutine_modifier($method) ) { + unless ($method) { + $method = $into->can($name) + or $self->throw_error("The method '$name' was not found in the inheritance hierarchy for $into"); + } + $method = Data::Util::modify_subroutine( $method, + $type => [$code] ); + + $self->add_method($name => $method); + } + else { + Data::Util::subroutine_modifier( $method, $type => $code ); + $self->add_method($name => Mouse::Util::get_code_ref($into, $name)); + } + return; }; } + # workaround older Perl's bug that caused segv :( + { + no warnings 'once'; + our $__not_used = \&_install_modifier; # keep the CV not to be released + } + # replace this method itself :) { no warnings 'redefine'; @@ -486,7 +479,7 @@ Mouse::Meta::Class - The Mouse class metaclass =head1 VERSION -This document describes Mouse version 0.50_06 +This document describes Mouse version 0.67 =head1 METHODS