3 package Devel::REPL::Plugin::DumpHistory;
4 # ABSTRACT: Plugin for Devel::REPL to save or print the history
6 our $VERSION = '1.003027';
8 use Devel::REPL::Plugin;
9 use namespace::autoclean;
11 ## Seems to be a sequence issue with requires
12 # requires qw{ history };
14 around 'read' => sub {
16 my ($self, @args) = @_;
18 my $line = $self->$orig(@args);
20 if ($line =~ m/^:dump ?(.*)$/) {
22 $self->print_history($file);
30 my ( $self, $file ) = @_;
33 open( my $fd, ">>", $file )
34 or do { warn "Couldn't open '$file': $!\n"; return; };
35 print $fd "$_\n" for ( @{ $self->history } );
36 $self->print( sprintf "Dumped %d history lines to '$file'\n",
37 scalar @{ $self->history } );
40 $self->print("$_\n") for ( @{ $self->history } );
55 my $repl = Devel::REPL->new;
56 $repl->load_plugin('LexEnv');
57 $repl->load_plugin('History');
58 $repl->load_plugin('DumpHistory');
63 Plugin that adds the C<:dump> and C<:dump file_name> commands to the
64 repl which will print the history to STDOUT or append the history to the
73 mgrimes, E<lt>mgrimes at cpan dot org<gt>
75 =head1 COPYRIGHT AND LICENSE
77 Copyright (C) 2007 by mgrimes
79 This library is free software; you can redistribute it and/or modify
80 it under the same terms as Perl itself, either Perl version 5.8.2 or,
81 at your option, any later version of Perl 5 you may have available.