diff options
author | Shawn M Moore <code@sartak.org> | 2013-06-27 13:37:10 -0400 |
---|---|---|
committer | Shawn M Moore <code@sartak.org> | 2013-06-27 13:39:29 -0400 |
commit | 0f576f029744b633cbce147d3681205f33001e2e (patch) | |
tree | e62dda947053ccb3c347204b64466ab297a9f04e /lib/Reply.pm | |
parent | 791b89f2b3d2ebdab4311ba2a60caf1be96d3466 (diff) | |
download | reply-0f576f029744b633cbce147d3681205f33001e2e.tar.gz reply-0f576f029744b633cbce147d3681205f33001e2e.zip |
Provide each plugin a tab_handler coderef option
Diffstat (limited to 'lib/Reply.pm')
-rw-r--r-- | lib/Reply.pm | 17 |
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; |