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=34a28d1058112ff3b656b372851e8e099b0e2c09;hp=e9c339ac9297aa427a00c69b41c4641bde7da17e;hb=HEAD;hpb=cf51843c3f3c45256998f34c54b22e910cbb8828 diff --git a/lib/Devel/REPL/Plugin/OutputCache.pm b/lib/Devel/REPL/Plugin/OutputCache.pm index e9c339a..34a28d1 100644 --- a/lib/Devel/REPL/Plugin/OutputCache.pm +++ b/lib/Devel/REPL/Plugin/OutputCache.pm @@ -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.003030'; + +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 also provides C<< $_REPL->output_cache >>, an array reference of all results in this session. -Devel::REPL already has a similar plugin, L. +L already has a similar plugin, L. 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 uses the C<_> sub for localization. Jifty is the +plugin. For example, L uses the C<_> sub for localization. L is the only known user. =head1 SEE ALSO