use Moose::Role;
use Carp qw/croak/;
-use Scalar::Util qw/weaken/;
+use Catalyst::Utils ();
use namespace::clean -except => 'meta';
+with 'Catalyst::Component::ContextClosure';
+
=head1 NAME
Catalyst::View::Component::SubInclude - Use subincludes in your Catalyst views
$self;
};
-around 'render' => sub {
- my $next = shift;
+before 'render' => sub {
my ($self, $c, @args) = @_;
-
- weaken $c;
-
- $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 {
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->generate_subinclude( $plugin_config, $c, @args );
}
sub _subinclude_plugin_class_name {