Switch subinclude generation to being called on instances.
[catagits/Catalyst-View-Component-SubInclude.git] / lib / Catalyst / View / Component / SubInclude.pm
index 20f3de5..dd0caea 100644 (file)
@@ -2,7 +2,10 @@ package Catalyst::View::Component::SubInclude;
 use Moose::Role;
 
 use Carp qw/croak/;
-use namespace::clean qw/croak/;
+use Catalyst::Utils ();
+use namespace::clean -except => 'meta';
+
+with 'Catalyst::Component::ContextClosure';
 
 =head1 NAME
 
@@ -10,11 +13,11 @@ Catalyst::View::Component::SubInclude - Use subincludes in your Catalyst views
 
 =head1 VERSION
 
-Version 0.04
+Version 0.07
 
 =cut
 
-our $VERSION = '0.04';
+our $VERSION = '0.07';
 
 =head1 SYNOPSIS
 
@@ -104,7 +107,7 @@ in runtime. It expects a fully qualified class name.
 
 has 'subinclude_plugin' => (
     is => 'rw',
-    isa => 'ClassName'
+    isa => 'Str'
 );
 
 around 'new' => sub {
@@ -119,14 +122,11 @@ around 'new' => sub {
     $self;
 };
 
-around 'render' => sub {
-    my $next = shift;
+before 'render' => sub {
     my ($self, $c, @args) = @_;
-    
-    $c->stash->{subinclude}       = sub { $self->_subinclude( $c, @_ ) };
-    $c->stash->{subinclude_using} = sub { $self->_subinclude_using( $c, @_ ) };
 
-    $self->$next( $c, @args );
+    $c->stash->{subinclude}       = $self->make_context_closure(sub { $self->_subinclude( @_ ) }, $c);
+    $c->stash->{subinclude_using} = $self->make_context_closure(sub { $self->_subinclude_using( @_ ) }, $c);
 };
 
 sub set_subinclude_plugin {
@@ -144,7 +144,8 @@ sub _subinclude {
 sub _subinclude_using {
     my ($self, $c, $plugin, @args) = @_;
     $plugin = $self->_subinclude_plugin_class_name($plugin);
-    $plugin->generate_subinclude( $c, @args );
+    my $plugin_config = Catalyst::Utils::merge_hashes($self->config->{subinclude}->{ALL}||{}, $self->config->{subinclude}->{$plugin}||{});
+    $plugin->new($plugin_config)->generate_subinclude( $c, @args );
 }
 
 sub _subinclude_plugin_class_name {