r79775@onn: sartak | 2009-02-06 15:56:59 -0500
[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 ;)
3#
4# epitaph, 22nd April 2007
5
6package Devel::REPL::Plugin::ReadLineHistory;
7
6a5409bc 8use Devel::REPL::Plugin;
9d03fe04 9
10my $hist_file=$ENV{PERLREPL_HISTFILE} ||
11 (($ENV{HOME} || (getpwuid($<))[7]) . "/.perlreplhist");
12# HISTLEN should probably be in a config file to stop people accidentally
13# truncating their history if they start the program and forget to set
14# PERLREPL_HISTLEN
15my $hist_len=$ENV{PERLREPL_HISTLEN} || 100;
16
17around 'run' => sub {
18 my $orig=shift;
19 my ($self, @args)=@_;
20 $self->term->stifle_history($hist_len);
21 -f($hist_file) && $self->term->ReadHistory($hist_file);
22 $self->term->Attribs->{do_expand}=1;
23 $self->$orig(@args);
24 $self->term->WriteHistory($hist_file) ||
25 $self->print("warning: failed to write history file $hist_file");
26};
27
281;
29
cfd1094b 30__END__
31
32=head1 NAME
33
34Devel::REPL::Plugin::ReadLineHistory - Integrate history with the facilities provided by L<Term::ReadLine>
35
36=cut
37