Commit | Line | Data |
24cc824f |
1 | package Devel::REPL::Plugin::Nopaste; |
2 | |
6a5409bc |
3 | use Devel::REPL::Plugin; |
24cc824f |
4 | use MooseX::AttributeHelpers; |
5 | use namespace::clean -except => [ 'meta' ]; |
a478012d |
6 | use Scalar::Util qw(blessed); |
24cc824f |
7 | |
3a400715 |
8 | sub BEFORE_PLUGIN { |
9 | my $self = shift; |
10 | $self->load_plugin('Turtles'); |
11 | } |
24cc824f |
12 | |
13 | has 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 | |
a4c582b6 |
24 | before eval => sub { |
24cc824f |
25 | my $self = shift; |
26 | my $line = shift; |
27 | |
24cc824f |
28 | # prepend each line with # |
29 | $line =~ s/^/# /mg; |
30 | |
a4c582b6 |
31 | $self->add_to_session($line . "\n"); |
32 | }; |
33 | |
34 | around eval => sub { |
35 | my $orig = shift; |
36 | my $self = shift; |
37 | my $line = shift; |
38 | |
39 | my @ret = $orig->($self, $line, @_); |
a478012d |
40 | my @ret_as_str = map { |
41 | if (!defined($_)) { |
42 | ''; |
43 | } elsif (blessed($_) && $_->can('stringify')) { |
44 | $_->stringify(); |
45 | } else { |
46 | $_; |
47 | } |
48 | } @ret; |
49 | |
50 | $self->add_to_session(join("\n", @ret_as_str) . "\n\n"); |
24cc824f |
51 | |
52 | return @ret; |
53 | }; |
54 | |
55 | sub command_nopaste { |
56 | my $self = shift; |
57 | |
58 | require App::Nopaste; |
59 | return App::Nopaste->nopaste( |
60 | text => $self->complete_session, |
61 | desc => "Devel::REPL session", |
62 | lang => "perl", |
63 | ); |
64 | } |
65 | |
66 | 1; |
67 | |
cfd1094b |
68 | __END__ |
69 | |
70 | =head1 NAME |
71 | |
72 | Devel::REPL::Plugin::Nopaste - #nopaste to upload session's input and output |
73 | |
30b459d4 |
74 | =head1 AUTHOR |
75 | |
76 | Shawn M Moore, C<< <sartak at gmail dot com> >> |
77 | |
cfd1094b |
78 | =cut |
79 | |