increment $VERSION after 1.003029 release
[p5sagit/Devel-REPL.git] / lib / Devel / REPL / Plugin / Nopaste.pm
CommitLineData
1716b200 1use strict;
2use warnings;
24cc824f 3package Devel::REPL::Plugin::Nopaste;
9d2a4940 4# ABSTRACT: #nopaste to upload session's input and output
24cc824f 5
77327851 6our $VERSION = '1.003030';
54beb05d 7
6a5409bc 8use Devel::REPL::Plugin;
e73ba6da 9use Moose::Util::TypeConstraints 'enum';
aa8b7647 10use namespace::autoclean;
a478012d 11use Scalar::Util qw(blessed);
24cc824f 12
3a400715 13sub BEFORE_PLUGIN {
14 my $self = shift;
15 $self->load_plugin('Turtles');
16}
24cc824f 17
18has complete_session => (
78bc5721 19 traits => ['String'],
24cc824f 20 is => 'rw',
21 isa => 'Str',
8995c74b 22 lazy => 1,
24cc824f 23 default => '',
8bf72450 24 handles => {
25 add_to_session => 'append',
24cc824f 26 },
27);
28
da4881b1 29has paste_title => (
da4881b1 30 is => 'rw',
31 isa => 'Str',
32 lazy => 1,
33 default => 'Devel::REPL session',
34);
35
76cd9acd 36has 'nopaste_format' => (
37 is => 'rw',
38 isa => enum( [qw[ comment_code comment_output ]] ),
39 lazy => 1,
40 default => 'comment_output',
41);
42
a4c582b6 43before eval => sub {
24cc824f 44 my $self = shift;
45 my $line = shift;
46
76cd9acd 47 if ( $self->nopaste_format() eq 'comment_code' ) {
48 # prepend each line with #
49 $line =~ s/^/# /mg;
50 }
24cc824f 51
a4c582b6 52 $self->add_to_session($line . "\n");
53};
54
55around eval => sub {
56 my $orig = shift;
57 my $self = shift;
58 my $line = shift;
59
60 my @ret = $orig->($self, $line, @_);
a478012d 61 my @ret_as_str = map {
62 if (!defined($_)) {
63 '';
64 } elsif (blessed($_) && $_->can('stringify')) {
65 $_->stringify();
66 } else {
67 $_;
68 }
69 } @ret;
70
76cd9acd 71 if ( $self->nopaste_format() eq 'comment_output' ) {
72 # prepend each line with #
73 map { $_ =~ s/^/# /mg } @ret_as_str;
74 }
75
a478012d 76 $self->add_to_session(join("\n", @ret_as_str) . "\n\n");
24cc824f 77
78 return @ret;
79};
80
81sub command_nopaste {
82 my $self = shift;
83
84 require App::Nopaste;
85 return App::Nopaste->nopaste(
86 text => $self->complete_session,
da4881b1 87 desc => $self->paste_title(),
24cc824f 88 lang => "perl",
89 );
90}
91
da4881b1 92sub command_pastetitle {
93 my ( $self, undef, $title ) = @_;
94
95 $self->paste_title( $title );
96}
97
24cc824f 981;
99
cfd1094b 100__END__
101
9d2a4940 102=pod
cfd1094b 103
da4881b1 104=head1 COMMANDS
105
106This module provides these commands to your Devel::REPL shell:
107
108=head2 #nopaste
109
110The C<#nopaste> sends a transcript of your session to a nopaste
111site.
112
113=head2 #pastetitle
114
115The C<#pastetitle> command allows you to set the title of the paste on
116the nopaste site. For example:
117
118C<#pastetitle example of some code>
119
8d5343b5 120defaults to C<'Devel::REPL session'>.
da4881b1 121
76cd9acd 122=head1 CONFIGURATION
123
124=head2 nopaste_format
125
126The format sent to the nopaste server can be adjusted with the
127C<nopaste_format> option. By default, the output of each perl
128statement is commented out, and the perl statements themselves are
129not. This can be reversed by setting the C<nopaste_format> attribute
130to C<comment_code> like this in your re.pl file:
131
132C<< $_REPL->nopaste_format( 'comment_code' ); >>
133
134The default of commenting out the output would be set like this:
135
136C<< $_REPL->nopaste_format( 'comment_output' ); >>
137
8d5343b5 138These options can be set during a L<Devel::REPL> session, but only affect
76cd9acd 139the future parts of the session, not the past parts.
140
30b459d4 141=head1 AUTHOR
142
143Shawn M Moore, C<< <sartak at gmail dot com> >>
144
da4881b1 145=head1 CONTRIBUTORS
146
147=over 4
148
149=item Andrew Moore - C<< <amoore@cpan.org> >>
150
151=back
152
cfd1094b 153=cut