From: nilson Date: Mon, 27 Jul 2009 23:33:19 +0000 (+0000) Subject: Fix some issues with Args/Captures in the SubRequest and Visit plugins and add more... X-Git-Tag: 0.07~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bdbd995d562de6e3e134fb54ae802579ad26539e;hp=dc6d45c0de64962dc0c093ff516b1056616a10e9;p=catagits%2FCatalyst-View-Component-SubInclude.git Fix some issues with Args/Captures in the SubRequest and Visit plugins and add more tests to the pseudo test suite --- diff --git a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm index 4b997c0..3a5658a 100644 --- a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm +++ b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm @@ -76,14 +76,15 @@ sub generate_subinclude { croak "subincludes through subrequests require Catalyst::Plugin::SubRequest" unless $c->can('sub_request'); - my $args = ref $params[0] eq 'ARRAY' ? shift @params : []; + my $args = ref $params[0] eq 'ARRAY' ? shift @params : []; + my $query = ref $params[-1] eq 'HASH' ? pop @params : {}; my $dispatcher = $c->dispatcher; my ($action) = $dispatcher->_invoke_as_path( $c, $path, $args ); my $uri = $c->uri_for( $action, $args, @params ); - $c->sub_request( $uri->path, $stash, @params ); + $c->sub_request( $uri->path, $stash, $query ); } =head1 SEE ALSO diff --git a/lib/Catalyst/View/Component/SubInclude/Visit.pm b/lib/Catalyst/View/Component/SubInclude/Visit.pm index 52ed67d..2d25883 100644 --- a/lib/Catalyst/View/Component/SubInclude/Visit.pm +++ b/lib/Catalyst/View/Component/SubInclude/Visit.pm @@ -63,8 +63,6 @@ sub generate_subinclude { croak "subincludes through visit() require Catalyst version 5.71000 or newer" unless $c->can('visit'); - - $c->log->debug("generate subinclude: $path @params"); { local $c->{stash} = {}; @@ -74,7 +72,8 @@ sub generate_subinclude { local $c->response->{body}; - $c->visit( $path, ( ref $params[0] eq 'ARRAY' ? shift @params : () ) ); + my $captures = ref $params[0] eq 'ARRAY' ? shift @params : []; + $c->visit( $path, \@params, $captures ); return $c->response->{body}; } diff --git a/t/ESITest/lib/ESITest/Controller/Root.pm b/t/ESITest/lib/ESITest/Controller/Root.pm index 78b78c8..a19c771 100644 --- a/t/ESITest/lib/ESITest/Controller/Root.pm +++ b/t/ESITest/lib/ESITest/Controller/Root.pm @@ -32,7 +32,7 @@ sub time_include : Chained('base') PathPart('time') Args(0) { sub capture : Chained('base') PathPart('') CaptureArgs(1) { my ( $self, $c, $arg ) = @_; $c->log->debug("Capture: $arg"); - $c->stash->{additional} = "Arg: $arg"; + $c->stash->{additional} = "Capture Arg: $arg"; } sub time_args : Chained('capture') PathPart('time') Args(0) { @@ -51,6 +51,42 @@ sub time_args : Chained('capture') PathPart('time') Args(0) { $c->stash->{template} = 'time_include.tt'; } +sub time_args_with_args : Chained('capture') PathPart('time') Args(1) { + my ( $self, $c, $arg ) = @_; + my $params = $c->req->params; + + $c->stash->{current_time} = localtime(); + + my $additional = $c->stash->{additional}; + for my $key (keys %$params) { + $additional .= " | $key = $params->{$key} | " + } + + $additional .= " Action Arg: $arg "; + + $c->stash->{additional} = $additional; + + $c->stash->{template} = 'time_include.tt'; +} + +sub time_args_without_capture : Chained('base') PathPart('time') Args(1) { + my ( $self, $c, $arg ) = @_; + my $params = $c->req->params; + + $c->stash->{current_time} = localtime(); + + my $additional = ''; + for my $key (keys %$params) { + $additional .= " | $key = $params->{$key} | " + } + + $additional .= " Action Arg: $arg "; + + $c->stash->{additional} = $additional; + + $c->stash->{template} = 'time_include.tt'; +} + sub end : ActionClass('RenderView') {} 1; diff --git a/t/ESITest/root/index.tt b/t/ESITest/root/index.tt index dd6e59f..913c888 100644 --- a/t/ESITest/root/index.tt +++ b/t/ESITest/root/index.tt @@ -9,4 +9,35 @@ Test subinclude using specific plugins:
[% subinclude_using('ESI', '/time_include', { 'plugin' => 'ESI'} ) %]


-[% subinclude_using('SubRequest', '/time_args', ['test'], { 'baz' => 'quux' }) %]
+ + +Test CaptureArgs and Args interaction (SubRequest):

+ +[% subinclude_using('SubRequest', '/time_args_with_args', ['capture_argtest'], 'regular_arg', { query_arg => 'val' } ) %]
+(using: [% c.uri_for( c.controller.action_for('time_args_with_args'), ['capture_argtest'], 'regular_arg', { query_arg => 'val' } ) %])
+
+ +[% subinclude_using('SubRequest', '/time_args_without_capture', 'regular_arg', { query_arg => 'val' }) %]
+(using: [% c.uri_for( c.controller.action_for('time_args_without_capture'), 'regular_arg', { query_arg => 'val' } ) %])
+ +

+ +Test CaptureArgs and Args interaction (Visit):

+ +[% subinclude_using('Visit', '/time_args_with_args', ['capture_argtest'], 'regular_arg', { query_arg => 'val' } ) %]
+(using: [% c.uri_for( c.controller.action_for('time_args_with_args'), ['capture_argtest'], 'regular_arg', { query_arg => 'val' } ) %])
+
+ +[% subinclude_using('Visit', '/time_args_without_capture', 'regular_arg', { query_arg => 'val' }) %]
+(using: [% c.uri_for( c.controller.action_for('time_args_without_capture'), 'regular_arg', { query_arg => 'val' } ) %])
+ +

+ +Test CaptureArgs and Args interaction (ESI):

+ +[% subinclude_using('ESI', '/time_args_with_args', ['capture_argtest'], 'regular_arg', { query_arg => 'val' } ) %]
+(using: [% c.uri_for( c.controller.action_for('time_args_with_args'), ['capture_argtest'], 'regular_arg', { query_arg => 'val' } ) %])
+
+ +[% subinclude_using('ESI', '/time_args_without_capture', 'regular_arg', { query_arg => 'val' }) %]
+(using: [% c.uri_for( c.controller.action_for('time_args_without_capture'), 'regular_arg', { query_arg => 'val' } ) %])