From 8df94620704fd56e5d0f718223f2b195181f57b6 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 30 May 2013 07:19:40 -0500 Subject: nopaste plugin --- dist.ini | 2 ++ lib/Reply/Plugin/Nopaste.pm | 76 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 lib/Reply/Plugin/Nopaste.pm diff --git a/dist.ini b/dist.ini index 1230162..ed1cb23 100644 --- a/dist.ini +++ b/dist.ini @@ -9,9 +9,11 @@ dist = Reply repository = github [AutoPrereqs] +skip = ^App::Nopaste$ skip = ^Data::Dump$ skip = ^Proc::InvokeEditor$ [Prereqs / RuntimeRecommends] +App::Nopaste = 0 Data::Dump = 0 Proc::InvokeEditor = 0 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; -- cgit v1.2.3-54-g00ecf