X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=blobdiff_plain;f=lib%2FDevel%2FREPL%2FPlugin%2FNopaste.pm;h=dcf83c4d6903ecbcbf51ce4a52bc33662ff1bfee;hp=5dd268cf2e8ee382e243e511d6d15f47f3ddb7b6;hb=e2d0b0198529e2e06593df8ebab7a8413bc932e1;hpb=6a5409bc859187db7d7553e4c19a559aeeba6430 diff --git a/lib/Devel/REPL/Plugin/Nopaste.pm b/lib/Devel/REPL/Plugin/Nopaste.pm index 5dd268c..dcf83c4 100644 --- a/lib/Devel/REPL/Plugin/Nopaste.pm +++ b/lib/Devel/REPL/Plugin/Nopaste.pm @@ -1,27 +1,51 @@ package Devel::REPL::Plugin::Nopaste; use Devel::REPL::Plugin; -use MooseX::AttributeHelpers; -use namespace::clean -except => [ 'meta' ]; +use namespace::sweep; +use Scalar::Util qw(blessed); +use MooX::Types::MooseLike::Base qw(Str); -with 'Devel::REPL::Plugin::Turtles'; +sub BEFORE_PLUGIN { + my $self = shift; + $self->load_plugin('Turtles'); +} has complete_session => ( - metaclass => 'String', is => 'rw', - isa => 'Str', - default => '', - provides => { - append => 'add_to_session', - }, + isa => Str, + lazy => 1, + default => sub { '' }, +); + +sub add_to_session { + my $self = shift; + my $session = $self->complete_session; + $session .= $_ for @_; + $self->complete_session($session); +} + +has paste_title => ( + is => 'rw', + isa => Str, + lazy => 1, + default => sub { 'Devel::REPL session' }, +); + +has 'nopaste_format' => ( + is => 'rw', + isa => sub { $_[0] =~ qr[^(?:comment_code|comment_output)$] }, + lazy => 1, + default => sub { 'comment_output' }, ); before eval => sub { my $self = shift; my $line = shift; - # prepend each line with # - $line =~ s/^/# /mg; + if ( $self->nopaste_format() eq 'comment_code' ) { + # prepend each line with # + $line =~ s/^/# /mg; + } $self->add_to_session($line . "\n"); }; @@ -32,8 +56,22 @@ around eval => sub { my $line = shift; my @ret = $orig->($self, $line, @_); - - $self->add_to_session(join("\n", @ret) . "\n\n"); + my @ret_as_str = map { + if (!defined($_)) { + ''; + } elsif (blessed($_) && $_->can('stringify')) { + $_->stringify(); + } else { + $_; + } + } @ret; + + if ( $self->nopaste_format() eq 'comment_output' ) { + # prepend each line with # + map { $_ =~ s/^/# /mg } @ret_as_str; + } + + $self->add_to_session(join("\n", @ret_as_str) . "\n\n"); return @ret; }; @@ -44,11 +82,17 @@ sub command_nopaste { require App::Nopaste; return App::Nopaste->nopaste( text => $self->complete_session, - desc => "Devel::REPL session", + desc => $self->paste_title(), lang => "perl", ); } +sub command_pastetitle { + my ( $self, undef, $title ) = @_; + + $self->paste_title( $title ); +} + 1; __END__ @@ -57,9 +101,54 @@ __END__ Devel::REPL::Plugin::Nopaste - #nopaste to upload session's input and output +=head1 COMMANDS + +This module provides these commands to your Devel::REPL shell: + +=head2 #nopaste + +The C<#nopaste> sends a transcript of your session to a nopaste +site. + +=head2 #pastetitle + +The C<#pastetitle> command allows you to set the title of the paste on +the nopaste site. For example: + +C<#pastetitle example of some code> + +defaults to 'Devel::REPL session' + +=head1 CONFIGURATION + +=head2 nopaste_format + +The format sent to the nopaste server can be adjusted with the +C option. By default, the output of each perl +statement is commented out, and the perl statements themselves are +not. This can be reversed by setting the C attribute +to C like this in your re.pl file: + +C<< $_REPL->nopaste_format( 'comment_code' ); >> + +The default of commenting out the output would be set like this: + +C<< $_REPL->nopaste_format( 'comment_output' ); >> + +These options can be set during a Devel::REPL session, but only affect +the future parts of the session, not the past parts. + =head1 AUTHOR Shawn M Moore, C<< >> +=head1 CONTRIBUTORS + +=over 4 + +=item Andrew Moore - C<< >> + +=back + =cut