X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=501c9ec3d9bf10188f7ed16ee19022c64eb36cc2;hb=825f7cdadcd71fb73aa7f6fa7c29b4f2d0c25366;hp=ba9d417f7bc2267381cc57d27d81a7ee2b612e59;hpb=8d5287a7df12b6fb0bdff2090220684913bdad04;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index ba9d417..501c9ec 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -1,5 +1,5 @@ package Mouse::Meta::Class; -use Mouse::Util qw/:meta get_linear_isa not_supported/; # enables strict and warnings +use Mouse::Util qw/:meta/; # enables strict and warnings use Scalar::Util qw/blessed weaken/; @@ -56,16 +56,25 @@ sub superclasses { if (@_) { foreach my $super(@_){ Mouse::Util::load_class($super); - my $meta = Mouse::Util::get_metaclass_by_name($super); - next if not defined $meta; + my $meta = Mouse::Util::get_metaclass_by_name($super); + unless(defined $meta) { + # checks if $super is a foreign class (i.e. non-Mouse class) + my $mm = $super->can('meta'); + if(!($mm && $mm == \&Mouse::Util::meta)) { + if($super->can('new') or $super->can('DESTROY')) { + $self->inherit_from_foreign_class($super); + } + } + next; + } if(Mouse::Util::is_a_metarole($meta)){ $self->throw_error("You cannot inherit from a Mouse Role ($super)"); } + # checks and fixes in metaclass compatiility next if $self->isa(ref $meta); # _superclass_meta_is_compatible - $self->_reconcile_with_superclass_meta($meta); } @{ $self->{superclasses} } = @_; @@ -73,6 +82,15 @@ sub superclasses { return @{ $self->{superclasses} }; } + +sub inherit_from_foreign_class { + my($class, $super) = @_; + Carp::carp("You inherit from non-Mouse class ($super)," + . " but it is unlikely to work correctly." + . " Please concider to use MouseX::Foreign"); + return; +} + my @MetaClassTypes = ( 'attribute', # Mouse::Meta::Attribute 'method', # Mouse::Meta::Method @@ -220,6 +238,12 @@ sub add_attribute { Carp::carp(qq{Attribute ($name) of class }.$self->name .qq{ has no associated methods (did you mean to provide an "is" argument?)}); } + + if(!Mouse::Util::MOUSE_XS) { + # in Mouse::PurePerl, attribute initialization code is cached, so it + # must be clear here. See _initialize_object() in Mouse::PurePerl. + delete $self->{_initialize_object}; + } return $attr; } @@ -257,8 +281,8 @@ sub make_immutable { ->_generate_destructor($self, \%args)); } - # Moose's make_immutable returns true allowing calling code to skip setting an explicit true value - # at the end of a source file. + # Moose's make_immutable returns true allowing calling code to skip + # setting an explicit true value at the end of a source file. return 1; } @@ -281,12 +305,15 @@ sub _install_modifier { my $modifier_table = $self->{modifiers}{$name}; if(!$modifier_table){ - my(@before, @after, @around, $cache, $modified); - - $cache = $original; - - $modified = sub { - for my $c (@before) { $c->(@_) } + my(@before, @after, @around); + my $cache = $original; + my $modified = sub { + if(@before) { + for my $c (@before) { $c->(@_) } + } + unless(@after) { + return $cache->(@_); + } if(wantarray){ # list context my @rval = $cache->(@_); @@ -424,7 +451,12 @@ Mouse::Meta::Class - The Mouse class metaclass =head1 VERSION -This document describes Mouse version 0.67 +This document describes Mouse version 0.74 + +=head1 DESCRIPTION + +This class is a meta object protocol for Mouse classes, +which is a subset of Moose::Meta:::Class. =head1 METHODS