| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 2 |  |  | 2 |  | 5044 | use strict; | 
|  | 2 |  |  |  |  | 8 |  | 
|  | 2 |  |  |  |  | 58 |  | 
| 2 | 2 |  |  | 2 |  | 11 | use warnings; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 115 |  | 
| 3 |  |  |  |  |  |  | # ABSTRACT: #nopaste to upload session's input and output | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | our $VERSION = '1.003029'; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | use Devel::REPL::Plugin; | 
| 8 | 2 |  |  | 2 |  | 12 | use Moose::Util::TypeConstraints 'enum'; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 9 | 2 |  |  | 2 |  | 8811 | use namespace::autoclean; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 21 |  | 
| 10 | 2 |  |  | 2 |  | 885 | use Scalar::Util qw(blessed); | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 19 |  | 
| 11 | 2 |  |  | 2 |  | 161 |  | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 1097 |  | 
| 12 |  |  |  |  |  |  | my $self = shift; | 
| 13 |  |  |  |  |  |  | $self->load_plugin('Turtles'); | 
| 14 | 1 |  |  | 1 | 0 | 3 | } | 
| 15 | 1 |  |  |  |  | 5 |  | 
| 16 |  |  |  |  |  |  | has complete_session => ( | 
| 17 |  |  |  |  |  |  | traits => ['String'], | 
| 18 |  |  |  |  |  |  | is        => 'rw', | 
| 19 |  |  |  |  |  |  | isa       => 'Str', | 
| 20 |  |  |  |  |  |  | lazy      => 1, | 
| 21 |  |  |  |  |  |  | default   => '', | 
| 22 |  |  |  |  |  |  | handles  => { | 
| 23 |  |  |  |  |  |  | add_to_session => 'append', | 
| 24 |  |  |  |  |  |  | }, | 
| 25 |  |  |  |  |  |  | ); | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | has paste_title => ( | 
| 28 |  |  |  |  |  |  | is        => 'rw', | 
| 29 |  |  |  |  |  |  | isa       => 'Str', | 
| 30 |  |  |  |  |  |  | lazy      => 1, | 
| 31 |  |  |  |  |  |  | default   => 'Devel::REPL session', | 
| 32 |  |  |  |  |  |  | ); | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | has 'nopaste_format' => ( | 
| 35 |  |  |  |  |  |  | is      => 'rw', | 
| 36 |  |  |  |  |  |  | isa     => enum( [qw[ comment_code comment_output ]] ), | 
| 37 |  |  |  |  |  |  | lazy    => 1, | 
| 38 |  |  |  |  |  |  | default => 'comment_output', | 
| 39 |  |  |  |  |  |  | ); | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | before eval => sub { | 
| 42 |  |  |  |  |  |  | my $self = shift; | 
| 43 |  |  |  |  |  |  | my $line = shift; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | if ( $self->nopaste_format() eq 'comment_code' ) { | 
| 46 |  |  |  |  |  |  | # prepend each line with # | 
| 47 |  |  |  |  |  |  | $line =~ s/^/# /mg; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | $self->add_to_session($line . "\n"); | 
| 51 |  |  |  |  |  |  | }; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | around eval => sub { | 
| 54 |  |  |  |  |  |  | my $orig = shift; | 
| 55 |  |  |  |  |  |  | my $self = shift; | 
| 56 |  |  |  |  |  |  | my $line = shift; | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | my @ret = $orig->($self, $line, @_); | 
| 59 |  |  |  |  |  |  | my @ret_as_str = map { | 
| 60 |  |  |  |  |  |  | if (!defined($_)) { | 
| 61 |  |  |  |  |  |  | ''; | 
| 62 |  |  |  |  |  |  | } elsif (blessed($_) && $_->can('stringify')) { | 
| 63 |  |  |  |  |  |  | $_->stringify(); | 
| 64 |  |  |  |  |  |  | } else { | 
| 65 |  |  |  |  |  |  | $_; | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  | } @ret; | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | if ( $self->nopaste_format() eq 'comment_output' ) { | 
| 70 |  |  |  |  |  |  | # prepend each line with # | 
| 71 |  |  |  |  |  |  | map { $_ =~ s/^/# /mg } @ret_as_str; | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | $self->add_to_session(join("\n", @ret_as_str) . "\n\n"); | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | return @ret; | 
| 77 |  |  |  |  |  |  | }; | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | my $self = shift; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | require App::Nopaste; | 
| 82 | 0 |  |  | 0 | 0 |  | return App::Nopaste->nopaste( | 
| 83 |  |  |  |  |  |  | text => $self->complete_session, | 
| 84 | 0 |  |  |  |  |  | desc => $self->paste_title(), | 
| 85 | 0 |  |  |  |  |  | lang => "perl", | 
| 86 |  |  |  |  |  |  | ); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | my ( $self, undef, $title ) = @_; | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | $self->paste_title( $title ); | 
| 92 |  |  |  |  |  |  | } | 
| 93 | 0 |  |  | 0 | 0 |  |  | 
| 94 |  |  |  |  |  |  | 1; | 
| 95 | 0 |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =pod | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =encoding UTF-8 | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =head1 NAME | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | Devel::REPL::Plugin::Nopaste - #nopaste to upload session's input and output | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | =head1 VERSION | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | version 1.003029 | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =head1 COMMANDS | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | This module provides these commands to your Devel::REPL shell: | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =head2 #nopaste | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | The C<#nopaste> sends a transcript of your session to a nopaste | 
| 116 |  |  |  |  |  |  | site. | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =head2 #pastetitle | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | The C<#pastetitle> command allows you to set the title of the paste on | 
| 121 |  |  |  |  |  |  | the nopaste site. For example: | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | C<#pastetitle example of some code> | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | defaults to C<'Devel::REPL session'>. | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head1 CONFIGURATION | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =head2 nopaste_format | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | The format sent to the nopaste server can be adjusted with the | 
| 132 |  |  |  |  |  |  | C<nopaste_format> option. By default, the output of each perl | 
| 133 |  |  |  |  |  |  | statement is commented out, and the perl statements themselves are | 
| 134 |  |  |  |  |  |  | not. This can be reversed by setting the C<nopaste_format> attribute | 
| 135 |  |  |  |  |  |  | to C<comment_code> like this in your re.pl file: | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | C<< $_REPL->nopaste_format( 'comment_code' ); >> | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | The default of commenting out the output would be set like this: | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | C<< $_REPL->nopaste_format( 'comment_output' ); >> | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | These options can be set during a L<Devel::REPL> session, but only affect | 
| 144 |  |  |  |  |  |  | the future parts of the session, not the past parts. | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | =head1 CONTRIBUTORS | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | =over 4 | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | =item Andrew Moore - C<< <amoore@cpan.org> >> | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =back | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =head1 SUPPORT | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Devel-REPL> | 
| 157 |  |  |  |  |  |  | (or L<bug-Devel-REPL@rt.cpan.org|mailto:bug-Devel-REPL@rt.cpan.org>). | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | There is also an irc channel available for users of this distribution, at | 
| 160 |  |  |  |  |  |  | L<C<#devel> on C<irc.perl.org>|irc://irc.perl.org/#devel-repl>. | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | =head1 AUTHOR | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | Shawn M Moore, C<< <sartak at gmail dot com> >> | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENCE | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | This software is copyright (c) 2007 by Matt S Trout - mst (at) shadowcatsystems.co.uk (L<http://www.shadowcatsystems.co.uk/>). | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 171 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | =cut |