Fixed inheritance bug
Sebastian Riedel [Thu, 3 Nov 2005 01:18:00 +0000 (01:18 +0000)]
lib/Catalyst/AttrContainer.pm
lib/Catalyst/Base.pm

index 23ca0a1..35741e4 100644 (file)
@@ -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 ();
 }
 
index f667fea..6a97984 100644 (file)
@@ -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