r63228@onn: sartak | 2008-06-25 05:01:43 -0400
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / ReadLineHistory.pm
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
6 package Devel::REPL::Plugin::ReadLineHistory;
7
8 use Devel::REPL::Plugin;
9
10 my $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
15 my $hist_len=$ENV{PERLREPL_HISTLEN} || 100;
16
17 around '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
28 1;
29
30 __END__
31
32 =head1 NAME
33
34 Devel::REPL::Plugin::ReadLineHistory - Integrate history with the facilities provided by L<Term::ReadLine>
35
36 =cut
37