diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-05-30 07:19:40 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-05-30 07:20:37 -0500 |
commit | 8df94620704fd56e5d0f718223f2b195181f57b6 (patch) | |
tree | 692b605edbe6e17d49fef9aede7e750eb6b357b8 /lib/Reply/Plugin/Nopaste.pm | |
parent | a3dcdb0d05d46a48e9305a34c4d4e0b954d50d9b (diff) | |
download | reply-8df94620704fd56e5d0f718223f2b195181f57b6.tar.gz reply-8df94620704fd56e5d0f718223f2b195181f57b6.zip |
nopaste plugin
Diffstat (limited to 'lib/Reply/Plugin/Nopaste.pm')
-rw-r--r-- | lib/Reply/Plugin/Nopaste.pm | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/Reply/Plugin/Nopaste.pm b/lib/Reply/Plugin/Nopaste.pm new file mode 100644 index 0000000..fdcead9 --- /dev/null +++ b/lib/Reply/Plugin/Nopaste.pm @@ -0,0 +1,76 @@ +package Reply::Plugin::Nopaste; +use strict; +use warnings; + +use base 'Reply::Plugin'; + +use App::Nopaste; + +# XXX note that this has to be loaded early, in order to catch all of the +# appropriate manipulations that plugins do ([DataDump], etc) + +sub new { + my $class = shift; + + my $self = $class->SUPER::new(@_); + $self->{history} = ''; + + return $self; +} + +sub prompt { + my $self = shift; + my ($next, @args) = @_; + my $prompt = $next->(@args); + $self->{prompt} = $prompt; + return $prompt; +} + +sub read_line { + my $self = shift; + my ($next, @args) = @_; + my $line = $next->(@args); + $self->{line} = "$line\n" if defined $line; + return $line; +} + +sub print_error { + my $self = shift; + my ($next, $error) = @_; + $self->{result} = $error; + $next->($error); +} + +sub print_result { + my $self = shift; + my ($next, @result) = @_; + $self->{result} = join('', @result) . "\n"; + $next->(@result); +} + +sub loop { + my $self = shift; + + my $prompt = delete $self->{prompt}; + my $line = delete $self->{line}; + my $result = delete $self->{result}; + + $self->{history} .= "$prompt$line$result"; +} + +sub command_nopaste { + my $self = shift; + my ($line) = @_; + + $line = "Reply session" unless length $line; + + App::Nopaste->nopaste( + text => $self->{history}, + desc => $line, + lang => 'perl', + ); + + return ''; +} + +1; |