From: acmoore Date: Mon, 23 Mar 2009 15:55:15 +0000 (+0000) Subject: Adding comment formatting option to the nopaste plugin X-Git-Tag: v1.003015~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-REPL.git;a=commitdiff_plain;h=76cd9acd4630d77ac67967cefcea99ec9591e1be;hp=da4881b1648ae6e76bf3d9387df92ef6c57a08a6 Adding comment formatting option to the nopaste plugin This patch adds the ability to configure the format of the session as is sent to the nopaste server. Formerly, the perl commands were commented out and the output of them was not. This patch provides a configuration option to swtich that behavior so that by default the perl code is not commented out, but the output from each statement is and this can be optionally switched back to the former behavior. git-svn-id: http://dev.catalyst.perl.org/repos/bast/trunk/Devel-REPL@5801 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- diff --git a/lib/Devel/REPL/Plugin/Nopaste.pm b/lib/Devel/REPL/Plugin/Nopaste.pm index e8baa53..2d9b8fc 100644 --- a/lib/Devel/REPL/Plugin/Nopaste.pm +++ b/lib/Devel/REPL/Plugin/Nopaste.pm @@ -2,6 +2,7 @@ package Devel::REPL::Plugin::Nopaste; use Devel::REPL::Plugin; use MooseX::AttributeHelpers; +use Moose::Util::TypeConstraints; use namespace::clean -except => [ 'meta' ]; use Scalar::Util qw(blessed); @@ -29,12 +30,21 @@ has paste_title => ( default => 'Devel::REPL session', ); +has 'nopaste_format' => ( + is => 'rw', + isa => enum( [qw[ comment_code comment_output ]] ), + lazy => 1, + default => '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"); }; @@ -55,6 +65,11 @@ around eval => sub { } } @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; @@ -103,6 +118,25 @@ 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<< >>