From 0f576f029744b633cbce147d3681205f33001e2e Mon Sep 17 00:00:00 2001 From: Shawn M Moore Date: Thu, 27 Jun 2013 13:37:10 -0400 Subject: Provide each plugin a tab_handler coderef option --- lib/Reply.pm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Reply.pm b/lib/Reply.pm index d5a3d4d..e1e31d2 100644 --- a/lib/Reply.pm +++ b/lib/Reply.pm @@ -4,7 +4,7 @@ use warnings; # ABSTRACT: read, eval, print, loop, yay! use Module::Runtime qw(compose_module_name require_module); -use Scalar::Util qw(blessed); +use Scalar::Util qw(blessed weaken); use Try::Tiny; use Reply::Config; @@ -188,7 +188,14 @@ sub _load_plugin { require_module($plugin); die "$plugin is not a valid plugin" unless $plugin->isa("Reply::Plugin"); - $plugin = $plugin->new(%$opts); + + my $weakself = $self; + weaken($weakself); + + $plugin = $plugin->new( + %$opts, + tab_handler => sub { $weakself->_tab_handler(@_) }, + ); } push @{ $self->{plugins} }, $plugin; @@ -254,6 +261,12 @@ sub _loop { $self->_chained_plugin('loop', 1); } +sub _tab_handler { + my $self = shift; + + $self->_concatenate_plugin('tab_handler', @_); +} + sub _wrapped_plugin { my $self = shift; my @plugins = ref($_[0]) ? @{ shift() } : $self->_plugins; -- cgit v1.2.3-54-g00ecf