X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=blobdiff_plain;f=lib%2FDevel%2FREPL%2FPlugin%2FOutputCache.pm;h=f1052e114470386a2e9366975b7db9e1f9130e4b;hp=e9c339ac9297aa427a00c69b41c4641bde7da17e;hb=1a00e38d3366bfa83804a7889161f2201f05ed24;hpb=cf51843c3f3c45256998f34c54b22e910cbb8828 diff --git a/lib/Devel/REPL/Plugin/OutputCache.pm b/lib/Devel/REPL/Plugin/OutputCache.pm index e9c339a..f1052e1 100644 --- a/lib/Devel/REPL/Plugin/OutputCache.pm +++ b/lib/Devel/REPL/Plugin/OutputCache.pm @@ -1,6 +1,6 @@ package Devel::REPL::Plugin::OutputCache; -use Moose::Role; +use Devel::REPL::Plugin; use namespace::clean -except => [ 'meta' ]; has output_cache => ( @@ -10,11 +10,29 @@ has output_cache => ( lazy => 1, ); +has warned_about_underscore => ( + is => 'rw', + isa => 'Bool', + default => 0, + lazy => 1, +); + around 'eval' => sub { my $orig = shift; my ($self, $line) = @_; - local *_ = sub () { $self->output_cache->[-1] }; + my $has_underscore = *_{CODE}; + if ($has_underscore && !$self->warned_about_underscore) { + warn "OutputCache: Sub _ already defined."; + $self->warned_about_underscore(1); + } + else { + # if _ is removed, then we should warn about it again if it comes back + $self->warned_about_underscore(0); + } + + # this needs to be a postfix conditional for 'local' to work + local *_ = sub () { $self->output_cache->[-1] } unless $has_underscore; my @ret; if (wantarray) {