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