Test for r11331 + fix to only report each action name once from get_action_methods
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Controller.pm
index 972b6a3..d52ae3f 100644 (file)
@@ -29,9 +29,9 @@ has action_namespace =>
      predicate => 'has_action_namespace',
     );
 
-has _controller_actions =>
+has actions =>
     (
-     is => 'rw',
+     accessor => '_controller_actions',
      isa => 'HashRef',
      init_arg => undef,
     );
@@ -137,21 +137,23 @@ around action_namespace => sub {
     my $orig = shift;
     my ( $self, $c ) = @_;
 
+    my $class = ref($self) || $self;
+    my $appclass = ref($c) || $c;
     if( ref($self) ){
         return $self->$orig if $self->has_action_namespace;
     } else {
-        return $self->config->{namespace} if exists $self->config->{namespace};
+        return $class->config->{namespace} if exists $class->config->{namespace};
     }
 
     my $case_s;
     if( $c ){
-        $case_s = $c->config->{case_sensitive};
+        $case_s = $appclass->config->{case_sensitive};
     } else {
         if ($self->isa('Catalyst')) {
-            $case_s = $self->config->{case_sensitive};
+            $case_s = $class->config->{case_sensitive};
         } else {
             if (ref $self) {
-                $case_s = $self->_application->config->{case_sensitive};
+                $case_s = ref($self->_application)->config->{case_sensitive};
             } else {
                 confess("Can't figure out case_sensitive setting");
             }
@@ -185,20 +187,23 @@ sub get_action_methods {
           . $meta->name
           . " cannot support register_actions." )
       unless $meta->can('get_nearest_methods_with_attributes');
-    my @methods = $meta->get_nearest_methods_with_attributes;
 
-    # actions specified via config are also action_methods
-    push(
-        @methods,
-        map {
+    # Find (and de-dup) action methods from attributes and those from config.
+    my %methods = (
+        map({ $_->name => 1 } $meta->get_nearest_methods_with_attributes),
+        %{ $self->_controller_actions }
+    );
+
+    if (ref $self) {
+        foreach (keys %methods) {
             $meta->find_method_by_name($_)
               || confess( 'Action "'
                   . $_
                   . '" is not available from controller '
-                  . ( ref $self ) )
-          } keys %{ $self->_controller_actions }
-    ) if ( ref $self );
-    return @methods;
+                  . ( ref $self ) );
+        }
+    }
+    return keys %methods;
 }