From: Sebastian Riedel Date: Thu, 3 Nov 2005 01:18:00 +0000 (+0000) Subject: Fixed inheritance bug X-Git-Tag: 5.7099_04~1041 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=57e4592849c4ec6ba7a0dea780ce8b2aa2de5606;hp=9619f23cf3582248bc6a324a975f37406e1efad4 Fixed inheritance bug --- diff --git a/lib/Catalyst/AttrContainer.pm b/lib/Catalyst/AttrContainer.pm index 23ca0a1..35741e4 100644 --- a/lib/Catalyst/AttrContainer.pm +++ b/lib/Catalyst/AttrContainer.pm @@ -13,8 +13,9 @@ __PACKAGE__->_action_cache( [] ); # note - see attributes(3pm) sub MODIFY_CODE_ATTRIBUTES { my ( $class, $code, @attrs ) = @_; - $class->_attr_cache({ %{$class->_attr_cache}, $code => [@attrs] }); - $class->_action_cache([ @{$class->_action_cache}, [ $code, [@attrs] ] ]); + $class->_attr_cache( { %{ $class->_attr_cache }, $code => [@attrs] } ); + $class->_action_cache( + [ @{ $class->_action_cache }, [ $code, [@attrs] ] ] ); return (); } diff --git a/lib/Catalyst/Base.pm b/lib/Catalyst/Base.pm index f667fea..6a97984 100644 --- a/lib/Catalyst/Base.pm +++ b/lib/Catalyst/Base.pm @@ -24,7 +24,7 @@ sub _DISPATCH : Private { sub _BEGIN : Private { my ( $self, $c ) = @_; - my $begin = ($c->get_actions( 'begin', $c->namespace))[-1]; + my $begin = ( $c->get_actions( 'begin', $c->namespace ) )[-1]; return 1 unless $begin; $begin->execute($c); return !@{ $c->error }; @@ -32,7 +32,7 @@ sub _BEGIN : Private { sub _AUTO : Private { my ( $self, $c ) = @_; - my @auto = $c->get_actions('auto', $c->namespace); + my @auto = $c->get_actions( 'auto', $c->namespace ); foreach my $auto (@auto) { $auto->execute($c); return 0 unless $c->state; @@ -48,7 +48,7 @@ sub _ACTION : Private { sub _END : Private { my ( $self, $c ) = @_; - my $end = ($c->get_actions( 'end', $c->namespace))[-1]; + my $end = ( $c->get_actions( 'end', $c->namespace ) )[-1]; return 1 unless $end; $end->execute($c); return !@{ $c->error }; @@ -56,25 +56,37 @@ sub _END : Private { sub action_namespace { my ( $self, $c ) = @_; - return - Catalyst::Utils::class2prefix( - ref $self, $c->config->{case_sensitive} ) || ''; + return Catalyst::Utils::class2prefix( ref $self, + $c->config->{case_sensitive} ) + || ''; } sub register_actions { my ( $self, $c ) = @_; my $class = ref $self || $self; - my $namespace = $self->action_namespace( $c ); + my $namespace = $self->action_namespace($c); my %methods; - $methods{$self->can($_)} = $_ for @{Class::Inspector->methods($class)||[]}; - foreach my $cache (@{$self->_action_cache}) { - my $code = $cache->[0]; + $methods{ $self->can($_) } = $_ + for @{ Class::Inspector->methods($class) || [] }; + + # Advanced inheritance support for plugins and the like + my @action_cache; + { + no strict 'refs'; + for my $isa ( @{"$class\::ISA"}, $class ) { + push @action_cache, @{ $isa->_action_cache } + if $isa->can('_action_cache'); + } + } + + foreach my $cache (@action_cache) { + my $code = $cache->[0]; my $method = $methods{$code}; next unless $method; - my $attrs = $self->_parse_attrs(@{$cache->[1]}); - if ($attrs->{Private} && ( keys %$attrs > 1 ) ) { + my $attrs = $self->_parse_attrs( @{ $cache->[1] } ); + if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) { $c->log->debug( 'Bad action definition "' - . join( ' ', @{$cache->[1]} ) + . join( ' ', @{ $cache->[1] } ) . qq/" for "$class->$method"/ ) if $c->debug; next; @@ -90,7 +102,7 @@ sub register_actions { attributes => $attrs, } ); - $c->dispatcher->register($c, $action); + $c->dispatcher->register( $c, $action ); } } @@ -112,7 +124,6 @@ sub _parse_attrs { return \%attributes; } - =head1 NAME Catalyst::Base - Catalyst Controller Base Class