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=38374e8707216a055fd7cceb14d7ac80ca5ec740;hp=e9c339ac9297aa427a00c69b41c4641bde7da17e;hb=6d22063d380fc145987db58a1b6222a33a596c3e;hpb=cf51843c3f3c45256998f34c54b22e910cbb8828 diff --git a/lib/Devel/REPL/Plugin/OutputCache.pm b/lib/Devel/REPL/Plugin/OutputCache.pm index e9c339a..38374e8 100644 --- a/lib/Devel/REPL/Plugin/OutputCache.pm +++ b/lib/Devel/REPL/Plugin/OutputCache.pm @@ -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) {