5dd268cf2e8ee382e243e511d6d15f47f3ddb7b6
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Nopaste.pm
1 package Devel::REPL::Plugin::Nopaste;
2
3 use Devel::REPL::Plugin;
4 use MooseX::AttributeHelpers;
5 use namespace::clean -except => [ 'meta' ];
6
7 with 'Devel::REPL::Plugin::Turtles';
8
9 has complete_session => (
10     metaclass => 'String',
11     is        => 'rw',
12     isa       => 'Str',
13     default   => '',
14     provides  => {
15         append => 'add_to_session',
16     },
17 );
18
19 before eval => sub {
20     my $self = shift;
21     my $line = shift;
22
23     # prepend each line with #
24     $line =~ s/^/# /mg;
25
26     $self->add_to_session($line . "\n");
27 };
28
29 around eval => sub {
30     my $orig = shift;
31     my $self = shift;
32     my $line = shift;
33
34     my @ret = $orig->($self, $line, @_);
35
36     $self->add_to_session(join("\n", @ret) . "\n\n");
37
38     return @ret;
39 };
40
41 sub command_nopaste {
42     my $self = shift;
43
44     require App::Nopaste;
45     return App::Nopaste->nopaste(
46         text => $self->complete_session,
47         desc => "Devel::REPL session",
48         lang => "perl",
49     );
50 }
51
52 1;
53
54 __END__
55
56 =head1 NAME
57
58 Devel::REPL::Plugin::Nopaste - #nopaste to upload session's input and output
59
60 =head1 AUTHOR
61
62 Shawn M Moore, C<< <sartak at gmail dot com> >>
63
64 =cut
65