X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FView%2FComponent%2FSubInclude%2FVisit.pm;h=88e883c2fd9a0e8345eb1b3dd8d09cc1f5a302d5;hb=HEAD;hp=b5fd93bbeb9c8b6c95fd37c9ade7b9c51b530fa1;hpb=3c5cb6d61dc75101ce515fde5dd66010cb1feeaf;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 b5fd93b..88e883c 100644 --- a/lib/Catalyst/View/Component/SubInclude/Visit.pm +++ b/lib/Catalyst/View/Component/SubInclude/Visit.pm @@ -1,9 +1,8 @@ package Catalyst::View::Component::SubInclude::Visit; -use warnings; -use strict; - +use Moose; use Carp qw/croak/; -use namespace::clean qw/croak/; +use MooseX::Types::Moose qw/ Bool /; +use namespace::clean -except => 'meta'; =head1 NAME @@ -11,11 +10,12 @@ Catalyst::View::Component::SubInclude::Visit - visit() plugin for C::V::Componen =head1 VERSION -Version 0.02 +Version 0.07_03 =cut -our $VERSION = '0.02'; +our $VERSION = '0.07_03'; +$VERSION = eval $VERSION; =head1 SYNOPSIS @@ -40,33 +40,61 @@ render subinclude contents. This method is only supported when using L version 5.71000 or newer. -=head1 CLASS METHODS +=head1 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. + +=head1 CONFIGURATION + +=head2 keep_stash + +You can choose to not localize the stash for Visits' subinclude calls. The subrequest +will have the same stash as the request that spawned it. Configure the keep_stash key +in your view: + + __PACKAGE__->config( + subinclude => { + 'Visit' => { + keep_stash => 1, + }, + } + ); + +Note: changes in the stash during a Visit subinclude will be visible after the include +returns. + =cut +has keep_stash => ( + isa => Bool, + is => 'ro', + default => 0, +); + sub generate_subinclude { - my ($class, $c, $path, @params) = @_; + my ($self, $c, $path, @params) = @_; 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->{stash} = $self->keep_stash ? $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 : () ) ); + my $captures = ref $params[0] eq 'ARRAY' ? shift @params : []; + $c->visit( $path, $captures, \@params ); return $c->response->{body}; } @@ -97,4 +125,5 @@ under the same terms as Perl itself. =cut +__PACKAGE__->meta->make_immutable; 1;