Adding #pastetitle command to Nopaste plugin
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Nopaste.pm
CommitLineData
24cc824f 1package Devel::REPL::Plugin::Nopaste;
2
6a5409bc 3use Devel::REPL::Plugin;
24cc824f 4use MooseX::AttributeHelpers;
5use namespace::clean -except => [ 'meta' ];
a478012d 6use Scalar::Util qw(blessed);
24cc824f 7
3a400715 8sub BEFORE_PLUGIN {
9 my $self = shift;
10 $self->load_plugin('Turtles');
11}
24cc824f 12
13has complete_session => (
14 metaclass => 'String',
15 is => 'rw',
16 isa => 'Str',
8995c74b 17 lazy => 1,
24cc824f 18 default => '',
19 provides => {
20 append => 'add_to_session',
21 },
22);
23
da4881b1 24has paste_title => (
25 metaclass => 'String',
26 is => 'rw',
27 isa => 'Str',
28 lazy => 1,
29 default => 'Devel::REPL session',
30);
31
a4c582b6 32before eval => sub {
24cc824f 33 my $self = shift;
34 my $line = shift;
35
24cc824f 36 # prepend each line with #
37 $line =~ s/^/# /mg;
38
a4c582b6 39 $self->add_to_session($line . "\n");
40};
41
42around eval => sub {
43 my $orig = shift;
44 my $self = shift;
45 my $line = shift;
46
47 my @ret = $orig->($self, $line, @_);
a478012d 48 my @ret_as_str = map {
49 if (!defined($_)) {
50 '';
51 } elsif (blessed($_) && $_->can('stringify')) {
52 $_->stringify();
53 } else {
54 $_;
55 }
56 } @ret;
57
58 $self->add_to_session(join("\n", @ret_as_str) . "\n\n");
24cc824f 59
60 return @ret;
61};
62
63sub command_nopaste {
64 my $self = shift;
65
66 require App::Nopaste;
67 return App::Nopaste->nopaste(
68 text => $self->complete_session,
da4881b1 69 desc => $self->paste_title(),
24cc824f 70 lang => "perl",
71 );
72}
73
da4881b1 74sub command_pastetitle {
75 my ( $self, undef, $title ) = @_;
76
77 $self->paste_title( $title );
78}
79
24cc824f 801;
81
cfd1094b 82__END__
83
84=head1 NAME
85
86Devel::REPL::Plugin::Nopaste - #nopaste to upload session's input and output
87
da4881b1 88=head1 COMMANDS
89
90This module provides these commands to your Devel::REPL shell:
91
92=head2 #nopaste
93
94The C<#nopaste> sends a transcript of your session to a nopaste
95site.
96
97=head2 #pastetitle
98
99The C<#pastetitle> command allows you to set the title of the paste on
100the nopaste site. For example:
101
102C<#pastetitle example of some code>
103
104defaults to 'Devel::REPL session'
105
30b459d4 106=head1 AUTHOR
107
108Shawn M Moore, C<< <sartak at gmail dot com> >>
109
da4881b1 110=head1 CONTRIBUTORS
111
112=over 4
113
114=item Andrew Moore - C<< <amoore@cpan.org> >>
115
116=back
117
cfd1094b 118=cut
119