From: Sartak Date: Sat, 1 Mar 2008 04:47:07 +0000 (+0000) Subject: OutputCache: If sub _ is already defined, then warn about it (once) and refuse to... X-Git-Tag: v1.003015~134 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=588f0734817915ab4f5763831e7f4ca45c235ce2;p=p5sagit%2FDevel-REPL.git OutputCache: If sub _ is already defined, then warn about it (once) and refuse to overwrite it git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@4112 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- 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) {