X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FView%2FComponent%2FSubInclude%2FVisit.pm;h=7ffae03cc9a237b2bd924849f2e9a779c753e5a9;hb=8bbd65bf6b13d05aae77781463bc43f3c0a44deb;hp=18555899cf60edb6a995b471474275cf4352bf1d;hpb=e88af2835e002b378e700d70a81912b493b40b1f;p=catagits%2FCatalyst-View-Component-SubInclude.git diff --git a/lib/Catalyst/View/Component/SubInclude/Visit.pm b/lib/Catalyst/View/Component/SubInclude/Visit.pm index 1855589..7ffae03 100644 --- a/lib/Catalyst/View/Component/SubInclude/Visit.pm +++ b/lib/Catalyst/View/Component/SubInclude/Visit.pm @@ -1,9 +1,7 @@ package Catalyst::View::Component::SubInclude::Visit; -use warnings; -use strict; - +use Moose; use Carp qw/croak/; -use namespace::clean qw/croak/; +use namespace::clean -except => 'meta'; =head1 NAME @@ -11,11 +9,11 @@ Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Componen =head1 VERSION -Version 0.02 +Version 0.07 =cut -our $VERSION = '0.02'; +our $VERSION = '0.07'; =head1 SYNOPSIS @@ -40,24 +38,44 @@ render subinclude contents. This method is only supported when using L version 5.71000 or newer. +B. Apparently, C doesn't handle this type +of actions yet. + =head1 CLASS METHODS =head2 C -This will translate to the following call: +This is (roughly) equivalent to the following call: $c->visit( $path, @args ); +But it will handle all the nasty details such as localizing the stash, +parameters and response body. This is necessary to keep behavior consistent +with the other plugins. + =cut sub generate_subinclude { - my ($class, $c, $path, @params) = @_; + my ($class, $config, $c, $path, @params) = @_; croak "subincludes through visit() require Catalyst version 5.71000 or newer" unless $c->can('visit'); - $c->visit( $path, @params ); - $c->res->{body}; + { + local $c->{stash} = $config->{keep_stash} ? $c->{stash} : {}; + + local $c->request->{parameters} = + ref $params[-1] eq 'HASH' ? pop @params : {}; + + local $c->response->{body}; + + my $captures = ref $params[0] eq 'ARRAY' ? shift @params : []; + $c->visit( $path, $captures, \@params ); + + return $c->response->{body}; + } + } =head1 SEE ALSO @@ -84,4 +102,5 @@ under the same terms as Perl itself. =cut +__PACKAGE__->meta->make_immutable; 1;