From: Nilson Santos Figueiredo JĂșnior Date: Thu, 5 Feb 2009 22:32:19 +0000 (+0000) Subject: Fix everything but visit is broken X-Git-Tag: 0.07_01~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-View-Component-SubInclude.git;a=commitdiff_plain;h=3c5cb6d61dc75101ce515fde5dd66010cb1feeaf Fix everything but visit is broken --- diff --git a/lib/Catalyst/View/Component/SubInclude/ESI.pm b/lib/Catalyst/View/Component/SubInclude/ESI.pm index 6d763e1..e8f446f 100644 --- a/lib/Catalyst/View/Component/SubInclude/ESI.pm +++ b/lib/Catalyst/View/Component/SubInclude/ESI.pm @@ -55,12 +55,14 @@ common interface for plugins. sub generate_subinclude { my ($class, $c, $path, @params) = @_; + my $args = ref $params[0] eq 'ARRAY' ? shift @params : []; + my $dispatcher = $c->dispatcher; - my ($action, $args) = $dispatcher->_invoke_as_path( $c, $path, @params ); + my ($action) = $dispatcher->_invoke_as_path( $c, $path, $args ); - my $uri = $c->uri_for( $action, $args ); + my $uri = $c->uri_for( $action, $args, @params ); - return ''; + return ''; } =head1 SEE ALSO diff --git a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm index 2e97236..982c0a6 100644 --- a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm +++ b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm @@ -71,11 +71,13 @@ 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 $dispatcher = $c->dispatcher; - my ($action, $args) = $dispatcher->_invoke_as_path( $c, $path, @params ); + my ($action) = $dispatcher->_invoke_as_path( $c, $path, $args ); - my $uri = $c->uri_for( $action, $args ); + my $uri = $c->uri_for( $action, $args, @params ); $c->sub_request( $uri->path, $stash, @params ); } diff --git a/lib/Catalyst/View/Component/SubInclude/Visit.pm b/lib/Catalyst/View/Component/SubInclude/Visit.pm index 1855589..b5fd93b 100644 --- a/lib/Catalyst/View/Component/SubInclude/Visit.pm +++ b/lib/Catalyst/View/Component/SubInclude/Visit.pm @@ -55,9 +55,22 @@ 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} = {}; + + local $c->request->{parameters} = + ref $params[-1] eq 'HASH' ? pop @params : {}; + + local $c->response->{body}; + + $c->visit( $path, ( ref $params[0] eq 'ARRAY' ? shift @params : () ) ); + + return $c->response->{body}; + } - $c->visit( $path, @params ); - $c->res->{body}; } =head1 SEE ALSO diff --git a/t/ESITest/lib/ESITest/Controller/Root.pm b/t/ESITest/lib/ESITest/Controller/Root.pm index 41b0ee8..78b78c8 100644 --- a/t/ESITest/lib/ESITest/Controller/Root.pm +++ b/t/ESITest/lib/ESITest/Controller/Root.pm @@ -16,7 +16,39 @@ sub base : Chained('/') PathPart('') CaptureArgs(0) { sub time_include : Chained('base') PathPart('time') Args(0) { my ( $self, $c ) = @_; + my $params = $c->req->params; + + $c->stash->{current_time} = localtime(); + + my $additional = ''; + for my $key (keys %$params) { + $additional .= "| $key = $params->{$key} | " + } + + $c->stash->{additional} = $additional; + +} + +sub capture : Chained('base') PathPart('') CaptureArgs(1) { + my ( $self, $c, $arg ) = @_; + $c->log->debug("Capture: $arg"); + $c->stash->{additional} = "Arg: $arg"; +} + +sub time_args : Chained('capture') PathPart('time') Args(0) { + my ( $self, $c ) = @_; + my $params = $c->req->params; + $c->stash->{current_time} = localtime(); + + my $additional = $c->stash->{additional}; + for my $key (keys %$params) { + $additional .= "| $key = $params->{$key} | " + } + + $c->stash->{additional} = $additional; + + $c->stash->{template} = 'time_include.tt'; } sub end : ActionClass('RenderView') {} diff --git a/t/ESITest/root/index.tt b/t/ESITest/root/index.tt index 73d6926..2bab3a9 100644 --- a/t/ESITest/root/index.tt +++ b/t/ESITest/root/index.tt @@ -1,2 +1,3 @@ ESI Test, will include /time_include
-[% subinclude('/time_include') %] +[% subinclude('/time_include', { 'foo' => 'bar'} ) %]
+[% subinclude('/time_args', ['test'], { 'baz' => 'quux' }) %]
diff --git a/t/ESITest/root/time_include.tt b/t/ESITest/root/time_include.tt index 43120f9..26ad8d8 100644 --- a/t/ESITest/root/time_include.tt +++ b/t/ESITest/root/time_include.tt @@ -1 +1 @@ -Current time is: [% current_time %] \ No newline at end of file +Current time is: [% current_time %] --> [% additional %]