| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::NoPaste; | 
| 2 | 1 |  |  | 1 |  | 27487 | use Spiffy 0.24 -Base; | 
|  | 1 |  |  |  |  | 6981 |  | 
|  | 1 |  |  |  |  | 11 |  | 
| 3 | 1 |  |  | 1 |  | 4994 | use LWP::UserAgent; | 
|  | 1 |  |  | 1 |  | 2 |  | 
|  | 1 |  |  | 1 |  | 32 |  | 
|  | 1 |  |  |  |  | 6 |  | 
|  | 1 |  |  |  |  | 7 |  | 
|  | 1 |  |  |  |  | 27 |  | 
|  | 1 |  |  |  |  | 4009 |  | 
|  | 1 |  |  |  |  | 197893 |  | 
|  | 1 |  |  |  |  | 45 |  | 
| 4 | 1 |  |  | 1 |  | 6885 | use HTTP::Request::Common 'POST'; | 
|  | 1 |  |  |  |  | 2525 |  | 
|  | 1 |  |  |  |  | 89 |  | 
| 5 | 1 |  |  | 1 |  | 1089 | use IO::All; | 
|  | 1 |  |  |  |  | 24172 |  | 
|  | 1 |  |  |  |  | 11 |  | 
| 6 | 1 |  |  | 1 |  | 1433 | use Clipboard; | 
|  | 1 |  |  |  |  | 29 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.03'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 0 |  |  | 0 | 0 |  | sub new { | 
| 10 | 0 |  |  |  |  |  | my %args = @_; | 
| 11 | 0 |  |  |  |  |  | bless { | 
| 12 |  |  |  |  |  |  | host => delete $args{host}, | 
| 13 |  |  |  |  |  |  | post_path => delete $args{post_path}, | 
| 14 |  |  |  |  |  |  | args => \%args, | 
| 15 |  |  |  |  |  |  | }, $self | 
| 16 |  |  |  |  |  |  | } | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 0 |  |  | 0 | 0 |  | sub send { | 
| 19 | 0 |  |  |  |  |  | my $text = shift; | 
| 20 | 0 |  |  |  |  |  | my $r = LWP::UserAgent->new->request( | 
| 21 |  |  |  |  |  |  | POST $self->{host} . $self->{post_path}, [ | 
| 22 | 0 |  |  |  |  |  | %{$self->{args}}, | 
| 23 |  |  |  |  |  |  | text => $text, | 
| 24 |  |  |  |  |  |  | ]); | 
| 25 | 0 | 0 |  |  |  |  | $self->response_die($r, "Didn't get a '302 Found'.") unless 302 == $r->code; | 
| 26 | 0 |  |  |  |  |  | my $p = $r->headers->header('Location'); | 
| 27 | 0 | 0 |  |  |  |  | $p =~ s/\.html$// or $self->response_die($r, "Location looks strange: $p"); | 
| 28 | 0 |  |  |  |  |  | $self->{payload_path} = $p; | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 0 |  |  | 0 | 0 |  | sub payload_urls { | 
| 32 | 0 |  |  |  |  |  | map { $self->{host} . $self->{payload_path} . '.' . $_ } qw(txt html) | 
|  | 0 |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 0 |  |  | 0 | 0 |  | sub read_from_stdin { | 
| 36 | 0 | 0 |  |  |  |  | print "Paste at will...\n" if -t STDIN; | 
| 37 | 0 |  |  |  |  |  | io('-')->all | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 0 |  |  | 0 | 0 |  | sub read_from_clipboard { Clipboard->paste } | 
|  | 0 |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 |  |  | 0 | 0 |  | sub save_to_clipboard { Clipboard->copy($_[0]); } | 
|  | 0 |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | my $PLEASE_EMAIL = "WebService::NoPaste has only been tested with 'pastebot' brand paste servers, and even then only to a limited extent.  If you got this error unexpectedly, please let me know - rking\@panopic.com."; | 
| 45 | 0 |  |  | 0 | 0 |  | sub response_die { | 
| 46 | 0 |  |  |  |  |  | my ($r, $reason) = @_; | 
| 47 | 0 |  |  |  |  |  | die join "\n", $reason, $PLEASE_EMAIL, "The response was: " .  $r->as_string | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | 1; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head1 NAME | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | WebService::NoPaste - Post to Paste Web Pages | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | # Manually paste input, manually copy the result url: | 
| 59 |  |  |  |  |  |  | $ nopaste | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | # Turbo mode: use clipboard as input, send, and then put the result | 
| 62 |  |  |  |  |  |  | # URL back into the clipboard: | 
| 63 |  |  |  |  |  |  | $ nopaste cp | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | # Just take the input from the clipboard, but otherwise leave the | 
| 66 |  |  |  |  |  |  | # clipboard alone: | 
| 67 |  |  |  |  |  |  | $ nopaste c | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | # Instantly upload your passwd file for the whole world to see, but | 
| 70 |  |  |  |  |  |  | # at least you'll have the result URL conveniently in your | 
| 71 |  |  |  |  |  |  | # clipboard. | 
| 72 |  |  |  |  |  |  | $ nopaste p < /etc/passwd | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | When online chatting it is problematic to paste an entire 300 line | 
| 77 |  |  |  |  |  |  | file.  Yes paste?  No.  NoPaste! | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | Posting to a paste host is preferred.  These servers are just web | 
| 80 |  |  |  |  |  |  | forms that accept input from a big text field, and temporarily house | 
| 81 |  |  |  |  |  |  | them as web pages. | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | This script/module is for those who find it tedious to switch to a | 
| 84 |  |  |  |  |  |  | web browser, load the page, and then paste.  Why use the mouse when | 
| 85 |  |  |  |  |  |  | you can use the keyboard? ;) | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =head1 CONFIGURATION | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | Currently, you just edit "nopaste" itself to point it at a different | 
| 90 |  |  |  |  |  |  | server, to change languages (which only affects the way the HTML | 
| 91 |  |  |  |  |  |  | formatting syntax highlights), etc. | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | This is lame, I know.  But it's early.  If you'd like neater | 
| 94 |  |  |  |  |  |  | configuration, email me, and I'll get right to it. | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =head1 AUTHOR | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | Ryan King | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | Copyright (c) 2005. Ryan King. All rights reserved. | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 105 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | See http://www.perl.com/perl/misc/Artistic.html | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =cut | 
| 110 |  |  |  |  |  |  | # vi:tw=72 |