summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn M Moore <code@sartak.org>2013-06-27 13:37:10 -0400
committerShawn M Moore <code@sartak.org>2013-06-27 13:39:29 -0400
commit0f576f029744b633cbce147d3681205f33001e2e (patch)
treee62dda947053ccb3c347204b64466ab297a9f04e
parent791b89f2b3d2ebdab4311ba2a60caf1be96d3466 (diff)
downloadreply-0f576f029744b633cbce147d3681205f33001e2e.tar.gz
reply-0f576f029744b633cbce147d3681205f33001e2e.zip
Provide each plugin a tab_handler coderef option
-rw-r--r--lib/Reply.pm17
1 files 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;