X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FView%2FComponent%2FSubInclude%2FSubRequest.pm;h=777cb353aad0b4646ea295170490316c4f6786af;hb=c7c06ff0cc2c5d128d7084843ed96288c76c53d6;hp=3a5658a446aed37ae5c97c591255215188f374f4;hpb=9c2c47b0e815f4d60ea7d51ebd0b584ec84ae2f6;p=catagits%2FCatalyst-View-Component-SubInclude.git diff --git a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm index 3a5658a..777cb35 100644 --- a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm +++ b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm @@ -1,9 +1,8 @@ package Catalyst::View::Component::SubInclude::SubRequest; -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::SubRequest - Sub-requests plugin for C::V =head1 VERSION -Version 0.05 +Version 0.07_03 =cut -our $VERSION = '0.05'; +our $VERSION = '0.07_03'; +$VERSION = eval $VERSION; =head1 SYNOPSIS @@ -51,7 +51,7 @@ to render the subinclude contents. It requires L. -=head1 CLASS METHODS +=head1 METHODS =head2 C @@ -69,20 +69,26 @@ common interface for all plugins. =cut +has keep_stash => ( + isa => Bool, + is => 'ro', + default => 0, +); + sub generate_subinclude { - my ($class, $c, $path, @params) = @_; - my $stash = {}; + my ($self, $c, $path, @params) = @_; + my $stash = $self->keep_stash ? { %{ $c->stash } } : {}; croak "subincludes through subrequests require Catalyst::Plugin::SubRequest" unless $c->can('sub_request'); - my $args = ref $params[0] eq 'ARRAY' ? shift @params : []; - my $query = ref $params[-1] eq 'HASH' ? pop @params : {}; + my $query = ref $params[-1] eq 'HASH' ? pop @params : {}; - my $dispatcher = $c->dispatcher; - my ($action) = $dispatcher->_invoke_as_path( $c, $path, $args ); + my $action = blessed($path) + ? $path + : $c->dispatcher->get_action_by_path($path); - my $uri = $c->uri_for( $action, $args, @params ); + my $uri = $c->uri_for( $action, @params ); $c->sub_request( $uri->path, $stash, $query ); } @@ -111,4 +117,5 @@ under the same terms as Perl itself. =cut +__PACKAGE__->meta->make_immutable; 1;