[Catalyst-commits] r11333 - in Catalyst-Runtime/5.80/trunk:
lib/Catalyst t
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Mon Sep 7 20:19:41 GMT 2009
Author: t0m
Date: 2009-09-07 20:19:40 +0000 (Mon, 07 Sep 2009)
New Revision: 11333
Added:
Catalyst-Runtime/5.80/trunk/t/unit_controller_actions.t
Modified:
Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm
Log:
Test for r11331 + fix to only report each action name once from get_action_methods
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm 2009-09-07 19:33:07 UTC (rev 11332)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/Controller.pm 2009-09-07 20:19:40 UTC (rev 11333)
@@ -187,20 +187,23 @@
. $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;
}
Added: Catalyst-Runtime/5.80/trunk/t/unit_controller_actions.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/unit_controller_actions.t (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/unit_controller_actions.t 2009-09-07 20:19:40 UTC (rev 11333)
@@ -0,0 +1,26 @@
+use strict;
+use warnings;
+use Test::More tests => 4;
+
+use Catalyst ();
+{
+ package TestController;
+ use Moose;
+ BEGIN { extends 'Catalyst::Controller' }
+
+ sub action : Local {}
+
+ sub foo : Path {}
+
+ no Moose;
+}
+
+my $mock_app = Class::MOP::Class->create_anon_class( superclasses => ['Catalyst'] );
+my $app = $mock_app->name->new;
+my $controller = TestController->new($app, {actions => { foo => { Path => '/some/path' }}});
+
+ok $controller->can('_controller_actions');
+is_deeply $controller->_controller_actions => { foo => { Path => '/some/path' }};
+is_deeply $controller->{actions} => { foo => { Path => '/some/path' }}; # Back compat.
+is_deeply [ sort grep { ! /^_/ } $controller->get_action_methods ], [sort qw/action foo/];
+
More information about the Catalyst-commits
mailing list