controller actions without attributes which are defined via config
Moritz Onken [Sun, 7 Jun 2009 11:14:23 +0000 (11:14 +0000)]
TODO
lib/Catalyst/Controller.pm
t/aggregate/live_component_controller_action_path.t
t/lib/TestApp/Controller/Action/Path.pm

diff --git a/TODO b/TODO
index fa6795c..fcade74 100644 (file)
--- a/TODO
+++ b/TODO
@@ -7,4 +7,6 @@ TODO for brach namespace_handling_refactor:
   * Catalyst::Controller::_parse_ActionClass_attr  # DONE
   * Catalyst::Dispatcher::_load_dispatch_types     # DONE
   * Catalyst::setup_plugins                        # DONE
-  to use the same namespacing method
\ No newline at end of file
+  to use the same namespacing method
+
+- Ok, so can you add tests for ->config(actions => { foo => { ActionClass => '+Bar' }});
\ No newline at end of file
index d1c6274..05165c1 100644 (file)
@@ -178,13 +178,28 @@ around path_prefix => sub {
 sub get_action_methods {
     my $self = shift;
     my $meta = find_meta($self);
-    confess("Metaclass for " . ref($meta) ." for " . $meta->name
-        . " cannot support register_actions.")
-        unless $meta->can('get_nearest_methods_with_attributes');
+    confess("Metaclass for "
+          . ref($meta) . " for "
+          . $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 {
+            $meta->get_method($_)
+              || confess( 'Action "' 
+                  . $_
+                  . '" is not available from controller '
+                  . ( ref $self ) )
+          } keys %{ $self->_controller_actions }
+    ) if ( ref $self );
     return @methods;
 }
 
+
 sub register_actions {
     my ( $self, $c ) = @_;
     $self->register_action_methods( $c, $self->get_action_methods );
@@ -199,7 +214,7 @@ sub register_action_methods {
     foreach my $method (@methods) {
         my $name = $method->name;
         my $attributes = $method->attributes;
-        next unless $attributes;
+        #next unless $attributes;
         my $attrs = $self->_parse_attrs( $c, $name, @{ $attributes } );
         if ( $attrs->{Private} && ( keys %$attrs > 1 ) ) {
             $c->log->debug( 'Bad action definition "'
index 338e696..950b4ac 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 36*$iters;
+use Test::More tests => 42*$iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -142,4 +142,22 @@ sub run_tests {
             'Content is a serialized Catalyst::Request'
         );
     }
+
+    {
+        ok( my $response = request('http://localhost/action/path/six'), 'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            'action/path/six', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::Path',
+            'Test Class'
+        );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
 }
index 3a93525..18fa71b 100644 (file)
@@ -7,6 +7,7 @@ __PACKAGE__->config(
     actions => {
       'one' => { 'Path' => [ 'a path with spaces' ] },
       'two' => { 'Path' => "åäö" },
+      'six' => { 'Local' => undef },
     },
 );
 
@@ -35,4 +36,9 @@ sub five : Path( "spaces_near_parens_doubleq" ) {
     $c->forward('TestApp::View::Dump::Request');
 }
 
+sub six {
+    my ( $self, $c ) = @_;
+    $c->forward('TestApp::View::Dump::Request');
+}
+
 1;