weave some pod, respecting overridden authors/legal
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / OutputCache.pm
index e9c339a..233fd50 100644 (file)
@@ -1,7 +1,12 @@
+use strict;
+use warnings;
 package Devel::REPL::Plugin::OutputCache;
+# ABSTRACT: Remember past results, _ is most recent
 
-use Moose::Role;
-use namespace::clean -except => [ 'meta' ];
+our $VERSION = '1.003027';
+
+use Devel::REPL::Plugin;
+use namespace::autoclean;
 
 has output_cache => (
     is      => 'rw',
@@ -10,11 +15,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) {
@@ -32,9 +55,7 @@ around 'eval' => sub {
 
 __END__
 
-=head1 NAME
-
-Devel::REPL::Plugin::OutputCache - remember past results, _ is most recent
+=pod
 
 =head1 SYNOPSIS
 
@@ -55,7 +76,7 @@ your result instead of having to type it in all at once, or store it in
 intermediate variables. C<OutputCache> also provides
 C<< $_REPL->output_cache >>, an array reference of all results in this session.
 
-Devel::REPL already has a similar plugin, L<Devel::REPL::Plugin::History>.
+L<Devel::REPL> already has a similar plugin, L<Devel::REPL::Plugin::History>.
 There are some key differences though:
 
 =over 4
@@ -83,7 +104,7 @@ does the parsing -- no surprises.
 
 The C<_> sub is shared across all packages. This means that if a module is
 using the C<_> sub, then there is a conflict and you should not use this
-plugin. For example, L<Jifty> uses the C<_> sub for localization. Jifty is the
+plugin. For example, L<Jifty> uses the C<_> sub for localization. L<Jifty> is the
 only known user.
 
 =head1 SEE ALSO