[Catalyst-commits] r6946 - in Catalyst-Runtime/5.80/trunk: .
lib/Catalyst/DispatchType t t/lib/TestApp/Controller/Action/Chained
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Tue Sep 25 22:24:01 GMT 2007
Author: matthewt
Date: 2007-09-25 22:24:00 +0100 (Tue, 25 Sep 2007)
New Revision: 6946
Added:
Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Chained/ArgsOrder.pm
Modified:
Catalyst-Runtime/5.80/trunk/
Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm
Catalyst-Runtime/5.80/trunk/t/live_component_controller_action_chained.t
Log:
r14301 at jules (orig r6945): gbjk | 2007-09-25 22:18:29 +0100
Chained Actions:
Fix Args() vs Args(0) action conflict with no further parts.
Args(0) should win.
Add tests to that affect.
Property changes on: Catalyst-Runtime/5.80/trunk
___________________________________________________________________
Name: svk:merge
- 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
+ 1c72fc7c-9ce4-42af-bf25-3bfe470ff1e8:/local/Catalyst/trunk/Catalyst-Runtime:9763
4ad37cd2-5fec-0310-835f-b3785c72a374:/Catalyst-Runtime/5.70/trunk:6945
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-ChildOf:4443
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-Runtime-jrockway:5857
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-component-setup:4320
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/Catalyst-docs:4325
4ad37cd2-5fec-0310-835f-b3785c72a374:/branches/current/Catalyst-Runtime:5142
4ad37cd2-5fec-0310-835f-b3785c72a374:/trunk/Catalyst-Runtime:6165
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime:8339
d7608cd0-831c-0410-93c0-e5b306c3c028:/local/Catalyst/Catalyst-Runtime-jrockway:8342
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime:6511
e56d974f-7718-0410-8b1c-b347a71765b2:/local/Catalyst-Runtime-current:10442
Modified: Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm 2007-09-25 21:18:29 UTC (rev 6945)
+++ Catalyst-Runtime/5.80/trunk/lib/Catalyst/DispatchType/Chained.pm 2007-09-25 21:24:00 UTC (rev 6946)
@@ -170,17 +170,28 @@
local $c->req->{arguments} = [ @{$c->req->args}, @parts ];
next TRY_ACTION unless $action->match($c);
}
- if (!$best_action || $#parts < $#{$best_action->{parts}}){
+ my $args_attr = $action->attributes->{Args}->[0];
+
+ # No best action currently
+ # OR This one matches with fewer parts left than the current best action,
+ # And therefore is a better match
+ # OR No parts and this expects 0
+ # The current best action might also be Args(0),
+ # but we couldn't chose between then anyway so we'll take the last seen
+
+ if (!$best_action ||
+ @parts < @{$best_action->{parts}} ||
+ (!@parts && $args_attr == 0)){
$best_action = {
actions => [ $action ],
captures=> [],
parts => \@parts
- }
}
+ }
}
}
}
- return @$best_action{qw/actions captures parts /} if $best_action;
+ return @$best_action{qw/actions captures parts/} if $best_action;
return ();
}
Added: Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Chained/ArgsOrder.pm
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Chained/ArgsOrder.pm (rev 0)
+++ Catalyst-Runtime/5.80/trunk/t/lib/TestApp/Controller/Action/Chained/ArgsOrder.pm 2007-09-25 21:24:00 UTC (rev 6946)
@@ -0,0 +1,35 @@
+package TestApp::Controller::Action::Chained::ArgsOrder;
+use warnings;
+use strict;
+
+use base qw( Catalyst::Controller );
+
+#
+# This controller builds a simple chain of three actions that
+# will output the arguments they got passed to @_ after the
+# context object. We do this to test if that passing works
+# as it should.
+#
+
+sub base :Chained('/') PathPart('argsorder') CaptureArgs(0) {
+ my ( $self, $c, $arg ) = @_;
+ push @{ $c->stash->{ passed_args } }, 'base', $arg;
+}
+
+sub index :Chained('base') PathPart('') Args(0) {
+ my ( $self, $c, $arg ) = @_;
+ push @{ $c->stash->{ passed_args } }, 'index', $arg;
+}
+
+sub all :Chained('base') PathPart('') Args() {
+ my ( $self, $c, $arg ) = @_;
+ push @{ $c->stash->{ passed_args } }, 'all', $arg;
+}
+
+sub end : Private {
+ my ( $self, $c ) = @_;
+ no warnings 'uninitialized';
+ $c->response->body( join '; ', @{ $c->stash->{ passed_args } } );
+}
+
+1;
Modified: Catalyst-Runtime/5.80/trunk/t/live_component_controller_action_chained.t
===================================================================
--- Catalyst-Runtime/5.80/trunk/t/live_component_controller_action_chained.t 2007-09-25 21:18:29 UTC (rev 6945)
+++ Catalyst-Runtime/5.80/trunk/t/live_component_controller_action_chained.t 2007-09-25 21:24:00 UTC (rev 6946)
@@ -10,7 +10,7 @@
BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
-use Test::More tests => 118*$iters;
+use Test::More tests => 124*$iters;
use Catalyst::Test 'TestApp';
if ( $ENV{CAT_BENCHMARK} ) {
@@ -766,66 +766,101 @@
is( $response->content, '; ', 'Content OK' );
}
- #
- # Higher Args() hiding more specific CaptureArgs chains sections
- #
- {
- my @expected = qw[
- TestApp::Controller::Action::Chained->begin
- TestApp::Controller::Action::Chained->cc_base
- TestApp::Controller::Action::Chained->cc_link
- TestApp::Controller::Action::Chained->cc_anchor
- TestApp::Controller::Action::Chained->end
- ];
+ #
+ # Higher Args() hiding more specific CaptureArgs chains sections
+ #
+ {
+ my @expected = qw[
+ TestApp::Controller::Action::Chained->begin
+ TestApp::Controller::Action::Chained->cc_base
+ TestApp::Controller::Action::Chained->cc_link
+ TestApp::Controller::Action::Chained->cc_anchor
+ TestApp::Controller::Action::Chained->end
+ ];
- my $expected = join ', ', @expected;
+ my $expected = join ', ', @expected;
- ok( my $response = request('http://localhost/chained/choose_capture/anchor.html'),
- 'Choose between an early Args() and a later more ideal chain' );
- is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
- is( $response->content => '; ', 'Content OK' );
- }
+ ok( my $response = request('http://localhost/chained/choose_capture/anchor.html'),
+ 'Choose between an early Args() and a later more ideal chain' );
+ is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
+ is( $response->content => '; ', 'Content OK' );
+ }
- #
- # Less specific chain not being seen correctly due to earlier looser capture
- #
- {
- my @expected = qw[
- TestApp::Controller::Action::Chained->begin
- TestApp::Controller::Action::Chained->cc_base
- TestApp::Controller::Action::Chained->cc_b
- TestApp::Controller::Action::Chained->cc_b_link
- TestApp::Controller::Action::Chained->cc_b_anchor
- TestApp::Controller::Action::Chained->end
- ];
+ #
+ # Less specific chain not being seen correctly due to earlier looser capture
+ #
+ {
+ my @expected = qw[
+ TestApp::Controller::Action::Chained->begin
+ TestApp::Controller::Action::Chained->cc_base
+ TestApp::Controller::Action::Chained->cc_b
+ TestApp::Controller::Action::Chained->cc_b_link
+ TestApp::Controller::Action::Chained->cc_b_anchor
+ TestApp::Controller::Action::Chained->end
+ ];
- my $expected = join ', ', @expected;
+ my $expected = join ', ', @expected;
- ok( my $response = request('http://localhost/chained/choose_capture/b/a/anchor.html'),
- 'Choose between a more specific chain and an earlier looser one' );
- is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
- is( $response->content => 'a; ', 'Content OK' );
- }
+ ok( my $response = request('http://localhost/chained/choose_capture/b/a/anchor.html'),
+ 'Choose between a more specific chain and an earlier looser one' );
+ is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
+ is( $response->content => 'a; ', 'Content OK' );
+ }
- #
- # Check we get the looser one when it's the correct match
- #
- {
- my @expected = qw[
- TestApp::Controller::Action::Chained->begin
- TestApp::Controller::Action::Chained->cc_base
- TestApp::Controller::Action::Chained->cc_a
- TestApp::Controller::Action::Chained->cc_a_link
- TestApp::Controller::Action::Chained->cc_a_anchor
- TestApp::Controller::Action::Chained->end
- ];
+ #
+ # Check we get the looser one when it's the correct match
+ #
+ {
+ my @expected = qw[
+ TestApp::Controller::Action::Chained->begin
+ TestApp::Controller::Action::Chained->cc_base
+ TestApp::Controller::Action::Chained->cc_a
+ TestApp::Controller::Action::Chained->cc_a_link
+ TestApp::Controller::Action::Chained->cc_a_anchor
+ TestApp::Controller::Action::Chained->end
+ ];
- my $expected = join ', ', @expected;
+ my $expected = join ', ', @expected;
- ok( my $response = request('http://localhost/chained/choose_capture/a/a/anchor.html'),
- 'Choose between a more specific chain and an earlier looser one' );
- is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
- is( $response->content => 'a; anchor.html', 'Content OK' );
- }
+ ok( my $response = request('http://localhost/chained/choose_capture/a/a/anchor.html'),
+ 'Choose between a more specific chain and an earlier looser one' );
+ is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
+ is( $response->content => 'a; anchor.html', 'Content OK' );
+ }
+ #
+ # Args(0) should win over Args() if we actually have no arguments.
+ {
+ my @expected = qw[
+ TestApp::Controller::Action::Chained->begin
+ TestApp::Controller::Action::Chained::ArgsOrder->base
+ TestApp::Controller::Action::Chained::ArgsOrder->index
+ TestApp::Controller::Action::Chained::ArgsOrder->end
+ ];
+
+ my $expected = join( ", ", @expected );
+
+ # With no args, we should run "index"
+ ok( my $response = request('http://localhost/argsorder/'),
+ 'Correct arg order ran' );
+ is( $response->header('X-Catalyst-Executed'),
+ $expected, 'Executed actions' );
+ is( $response->content, 'base; ; index; ', 'Content OK' );
+
+ # With args given, run "all"
+ ok( $response = request('http://localhost/argsorder/X'),
+ 'Correct arg order ran' );
+ is( $response->header('X-Catalyst-Executed'),
+ join(", ",
+ qw[
+ TestApp::Controller::Action::Chained->begin
+ TestApp::Controller::Action::Chained::ArgsOrder->base
+ TestApp::Controller::Action::Chained::ArgsOrder->all
+ TestApp::Controller::Action::Chained::ArgsOrder->end
+ ])
+ );
+ is( $response->content, 'base; ; all; X', 'Content OK' );
+
+ }
+
}
More information about the Catalyst-commits
mailing list