increment $VERSION after 1.003028 release
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Nopaste.pm
index e8baa53..fe35ca8 100644 (file)
@@ -1,8 +1,13 @@
+use strict;
+use warnings;
 package Devel::REPL::Plugin::Nopaste;
+# ABSTRACT: #nopaste to upload session's input and output
+
+our $VERSION = '1.003029';
 
 use Devel::REPL::Plugin;
-use MooseX::AttributeHelpers;
-use namespace::clean -except => [ 'meta' ];
+use Moose::Util::TypeConstraints 'enum';
+use namespace::autoclean;
 use Scalar::Util qw(blessed);
 
 sub BEFORE_PLUGIN {
@@ -11,30 +16,38 @@ sub BEFORE_PLUGIN {
 }
 
 has complete_session => (
-    metaclass => 'String',
+    traits => ['String'],
     is        => 'rw',
     isa       => 'Str',
     lazy      => 1,
     default   => '',
-    provides  => {
-        append => 'add_to_session',
+    handles  => {
+        add_to_session => 'append',
     },
 );
 
 has paste_title => (
-    metaclass => 'String',
     is        => 'rw',
     isa       => 'Str',
     lazy      => 1,
     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 +68,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;
@@ -81,9 +99,7 @@ sub command_pastetitle {
 
 __END__
 
-=head1 NAME
-
-Devel::REPL::Plugin::Nopaste - #nopaste to upload session's input and output
+=pod
 
 =head1 COMMANDS
 
@@ -101,7 +117,26 @@ the nopaste site. For example:
 
 C<#pastetitle example of some code>
 
-defaults to 'Devel::REPL session'
+defaults to C<'Devel::REPL session'>.
+
+=head1 CONFIGURATION
+
+=head2 nopaste_format
+
+The format sent to the nopaste server can be adjusted with the
+C<nopaste_format> 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<nopaste_format> attribute
+to C<comment_code> 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 L<Devel::REPL> session, but only affect
+the future parts of the session, not the past parts.
 
 =head1 AUTHOR
 
@@ -116,4 +151,3 @@ Shawn M Moore, C<< <sartak at gmail dot com> >>
 =back
 
 =cut
-