Fix typo in ReadLineHistory plugin
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / ReadLineHistory.pm
CommitLineData
9d03fe04 1# First cut at using the readline history directly rather than reimplementing
2# it. It does save history but it's a little crappy; still playing with it ;)
e4761e81 3#
9d03fe04 4# epitaph, 22nd April 2007
5
6package Devel::REPL::Plugin::ReadLineHistory;
7
6a5409bc 8use Devel::REPL::Plugin;
ef59b3d9 9use File::HomeDir;
10use File::Spec;
11
12my $hist_file = $ENV{PERLREPL_HISTFILE} ||
13 File::Spec->catfile(File::HomeDir->my_home, '.perlreplhist');
9d03fe04 14
9d03fe04 15# HISTLEN should probably be in a config file to stop people accidentally
16# truncating their history if they start the program and forget to set
17# PERLREPL_HISTLEN
18my $hist_len=$ENV{PERLREPL_HISTLEN} || 100;
19
20around 'run' => sub {
21 my $orig=shift;
22 my ($self, @args)=@_;
4906ca4e 23 if ($self->term->ReadLine eq 'Term::ReadLine::Gnu') {
7907c13e 24 $self->term->stifle_history($hist_len);
25 }
4906ca4e 26 if ($self->term->ReadLine eq 'Term::ReadLine::Perl') {
7907c13e 27 $self->term->Attribs->{MaxHistorySize} = $hist_len;
28 }
9d03fe04 29 -f($hist_file) && $self->term->ReadHistory($hist_file);
30 $self->term->Attribs->{do_expand}=1;
31 $self->$orig(@args);
32 $self->term->WriteHistory($hist_file) ||
33 $self->print("warning: failed to write history file $hist_file");
34};
35
361;
37
cfd1094b 38__END__
39
40=head1 NAME
41
42Devel::REPL::Plugin::ReadLineHistory - Integrate history with the facilities provided by L<Term::ReadLine>
43
44=cut
45