Adding #pastetitle command to Nopaste plugin
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Nopaste.pm
index 40fa76d..e8baa53 100644 (file)
@@ -3,6 +3,7 @@ package Devel::REPL::Plugin::Nopaste;
 use Devel::REPL::Plugin;
 use MooseX::AttributeHelpers;
 use namespace::clean -except => [ 'meta' ];
+use Scalar::Util qw(blessed);
 
 sub BEFORE_PLUGIN {
     my $self = shift;
@@ -20,6 +21,14 @@ has complete_session => (
     },
 );
 
+has paste_title => (
+    metaclass => 'String',
+    is        => 'rw',
+    isa       => 'Str',
+    lazy      => 1,
+    default   => 'Devel::REPL session',
+);
+
 before eval => sub {
     my $self = shift;
     my $line = shift;
@@ -36,8 +45,17 @@ 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;
+
+    $self->add_to_session(join("\n", @ret_as_str) . "\n\n");
 
     return @ret;
 };
@@ -48,11 +66,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__
@@ -61,9 +85,35 @@ __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 AUTHOR
 
 Shawn M Moore, C<< <sartak at gmail dot com> >>
 
+=head1 CONTRIBUTORS
+
+=over 4
+
+=item Andrew Moore - C<< <amoore@cpan.org> >>
+
+=back
+
 =cut