+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.003029';
+
+use Devel::REPL::Plugin;
+use namespace::autoclean;
has output_cache => (
is => 'rw',
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) {
__END__
-=head1 NAME
-
-Devel::REPL::Plugin::OutputCache - remember past results, _ is most recent
+=pod
=head1 SYNOPSIS
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
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