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