X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=187ba003ab749e5fcdea81833f68647e492db3d1;hb=902174eb6dc2afbe8a2b8fb0a27446b3276787d8;hp=b815ea891bad39ef022f519e0196f0fd80bbbf43;hpb=503ed64839f2938fc29e8bfbfb21f631a0c4ccda;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index b815ea8..187ba00 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -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 @@ -281,19 +299,16 @@ sub _install_modifier { my $modifier_table = $self->{modifiers}{$name}; if(!$modifier_table){ - my(@before, @after, $cache); - - $cache = $original; - - my $around_only = ($type eq 'around'); - + my(@before, @after, @around); + my $cache = $original; my $modified = sub { - if($around_only) { + if(@before) { + for my $c (@before) { $c->(@_) } + } + unless(@after) { return $cache->(@_); } - for my $c (@before) { $c->(@_) } - if(wantarray){ # list context my @rval = $cache->(@_); @@ -319,8 +334,7 @@ sub _install_modifier { before => \@before, after => \@after, - around => \my @around, - around_only => \$around_only, + around => \@around, cache => \$cache, # cache for around modifiers }; @@ -329,11 +343,9 @@ sub _install_modifier { } 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 @@ -433,7 +445,7 @@ Mouse::Meta::Class - The Mouse class metaclass =head1 VERSION -This document describes Mouse version 0.67 +This document describes Mouse version 0.70 =head1 DESCRIPTION