X-Git-Url: http://wagnertech.de/git?p=kivitendo-erp.git;a=blobdiff_plain;f=Devel%2FREPL%2FPlugin%2FPermanentHistory.pm;fp=Devel%2FREPL%2FPlugin%2FPermanentHistory.pm;h=3a46b56cf28435c50a20659c8da82a4cd773a93b;hp=0000000000000000000000000000000000000000;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44 diff --git a/Devel/REPL/Plugin/PermanentHistory.pm b/Devel/REPL/Plugin/PermanentHistory.pm new file mode 100644 index 000000000..3a46b56cf --- /dev/null +++ b/Devel/REPL/Plugin/PermanentHistory.pm @@ -0,0 +1,39 @@ +package Devel::REPL::Plugin::PermanentHistory; + +use Moose::Role; +use namespace::clean -except => [ 'meta' ]; +use File::Slurp; +use Data::Dumper; + +has 'history_file' => ( is => 'rw' ); + +sub load_history { + my $self = shift; + my $file = shift; + + $self->history_file( $file ); + + return unless $self->history_file && -f $self->history_file; + + my @history = + map { chomp; $_ } + read_file($self->history_file); +# print Dumper(\@history); + $self->history( \@history ); + $self->term->addhistory($_) for @history; +} + +before 'DESTROY' => sub { + my $self = shift; + + return unless $self->history_file; + + write_file $self->history_file, + map { $_, $/ } + grep $_, + grep { !/^quit\b/ } + @{ $self->history }; +}; + +1; +