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
=head1 VERSION
-Version 0.05
+Version 0.07_03
=cut
-our $VERSION = '0.05';
+our $VERSION = '0.07_03';
+$VERSION = eval $VERSION;
=head1 SYNOPSIS
This method is only supported when using L<Catalyst> version 5.71000 or newer.
-B<WARNING: As of Catalyst version 5.71000, this plugin doesn't work for chained
-actions with captured arguments>. Apparently, C<visit> doesn't handle this type
-of actions yet.
-
-=head1 CLASS METHODS
+=head1 METHODS
=head2 C<generate_subinclude( $c, $path, @args )>
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');
{
- 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};
my $captures = ref $params[0] eq 'ARRAY' ? shift @params : [];
- $c->visit( $path, \@params, $captures );
+ $c->visit( $path, $captures, \@params );
return $c->response->{body};
}
=cut
+__PACKAGE__->meta->make_immutable;
1;