[Bast-commits] r4112 - trunk/Devel-REPL/lib/Devel/REPL/Plugin

Sartak at dev.catalyst.perl.org Sartak at dev.catalyst.perl.org
Sat Mar 1 04:47:07 GMT 2008


Author: Sartak
Date: 2008-03-01 04:47:07 +0000 (Sat, 01 Mar 2008)
New Revision: 4112

Modified:
   trunk/Devel-REPL/lib/Devel/REPL/Plugin/OutputCache.pm
Log:
OutputCache: If sub _ is already defined, then warn about it (once) and refuse to overwrite it


Modified: trunk/Devel-REPL/lib/Devel/REPL/Plugin/OutputCache.pm
===================================================================
--- trunk/Devel-REPL/lib/Devel/REPL/Plugin/OutputCache.pm	2008-02-29 02:11:16 UTC (rev 4111)
+++ trunk/Devel-REPL/lib/Devel/REPL/Plugin/OutputCache.pm	2008-03-01 04:47:07 UTC (rev 4112)
@@ -10,12 +10,30 @@
     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) {
         @ret = $self->$orig($line);




More information about the Bast-commits mailing list