From: Tomas Doran Date: Sun, 24 Jan 2010 22:51:25 +0000 (+0000) Subject: Switch subinclude generation to being called on instances. X-Git-Tag: 0.07_01~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-View-Component-SubInclude.git;a=commitdiff_plain;h=f97c716560e114d118695339a200fe5a7e09e9e5;hp=8bbd65bf6b13d05aae77781463bc43f3c0a44deb Switch subinclude generation to being called on instances. Instances need to be cached but aren't yet --- diff --git a/Makefile.PL b/Makefile.PL index 3e8a8dd..5bd0796 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -11,6 +11,7 @@ requires 'Catalyst::Runtime' => '5.80014'; requires 'Catalyst::Plugin::SubRequest'; requires 'Moose'; requires 'Moose::Role'; +requires 'MooseX::Types'; requires 'Carp'; requires 'namespace::clean'; diff --git a/lib/Catalyst/View/Component/SubInclude.pm b/lib/Catalyst/View/Component/SubInclude.pm index 045cb9d..dd0caea 100644 --- a/lib/Catalyst/View/Component/SubInclude.pm +++ b/lib/Catalyst/View/Component/SubInclude.pm @@ -145,7 +145,7 @@ sub _subinclude_using { my ($self, $c, $plugin, @args) = @_; $plugin = $self->_subinclude_plugin_class_name($plugin); my $plugin_config = Catalyst::Utils::merge_hashes($self->config->{subinclude}->{ALL}||{}, $self->config->{subinclude}->{$plugin}||{}); - $plugin->generate_subinclude( $plugin_config, $c, @args ); + $plugin->new($plugin_config)->generate_subinclude( $c, @args ); } sub _subinclude_plugin_class_name { diff --git a/lib/Catalyst/View/Component/SubInclude/ESI.pm b/lib/Catalyst/View/Component/SubInclude/ESI.pm index 8909f9f..259f8cc 100644 --- a/lib/Catalyst/View/Component/SubInclude/ESI.pm +++ b/lib/Catalyst/View/Component/SubInclude/ESI.pm @@ -55,7 +55,7 @@ common interface for plugins. =cut sub generate_subinclude { - my ($class, $config, $c, $path, @params) = @_; + my ($self, $c, $path, @params) = @_; my $uri = $c->uri_for_action( $path, @params ); diff --git a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm index b931a74..18260dc 100644 --- a/lib/Catalyst/View/Component/SubInclude/SubRequest.pm +++ b/lib/Catalyst/View/Component/SubInclude/SubRequest.pm @@ -1,6 +1,7 @@ package Catalyst::View::Component::SubInclude::SubRequest; use Moose; use Carp qw/croak/; +use MooseX::Types::Moose qw/ Bool /; use namespace::clean -except => 'meta'; =head1 NAME @@ -67,9 +68,15 @@ common interface for all plugins. =cut +has keep_stash => ( + isa => Bool, + is => 'ro', + default => 0, +); + sub generate_subinclude { - my ($class, $config, $c, $path, @params) = @_; - my $stash = $config->{keep_stash} ? { %{ $c->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'); diff --git a/lib/Catalyst/View/Component/SubInclude/Visit.pm b/lib/Catalyst/View/Component/SubInclude/Visit.pm index 7ffae03..5cfc85a 100644 --- a/lib/Catalyst/View/Component/SubInclude/Visit.pm +++ b/lib/Catalyst/View/Component/SubInclude/Visit.pm @@ -1,6 +1,7 @@ package Catalyst::View::Component::SubInclude::Visit; use Moose; use Carp qw/croak/; +use MooseX::Types::Moose qw/ Bool /; use namespace::clean -except => 'meta'; =head1 NAME @@ -56,14 +57,20 @@ with the other plugins. =cut +has keep_stash => ( + isa => Bool, + is => 'ro', + default => 0, +); + sub generate_subinclude { - my ($class, $config, $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} = $config->{keep_stash} ? $c->{stash} : {}; + local $c->{stash} = $self->keep_stash ? $c->{stash} : {}; local $c->request->{parameters} = ref $params[-1] eq 'HASH' ? pop @params : {};