| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::Nopaste::Service::AnyPastebin; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 23639 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 34 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 5 | 1 |  |  | 1 |  | 5 | use Scalar::Util 'blessed'; | 
|  | 1 |  |  |  |  | 6 |  | 
|  | 1 |  |  |  |  | 113 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 5 | use base q[App::Nopaste::Service]; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 1273 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our $VERSION = '0.04'; | 
| 10 |  |  |  |  |  |  |  | 
| 11 | 0 |  |  | 0 | 1 |  | sub uri { return 'http://pastebin.com/' } | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 0 |  |  | 0 | 1 |  | sub forbid_in_default { 0 } | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub get { | 
| 16 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 17 | 0 |  |  |  |  |  | my $mech = shift; | 
| 18 | 0 |  |  |  |  |  | my %args = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 0 | 0 | 0 |  |  |  | $mech->{__username} = $args{username} | 
| 21 |  |  |  |  |  |  | if exists($args{username}) && $args{username}; | 
| 22 | 0 | 0 | 0 |  |  |  | $mech->{__password} = $args{password} | 
| 23 |  |  |  |  |  |  | if exists($args{password}) && $args{password}; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 0 |  |  |  |  |  | return $self->SUPER::get($mech => @_); | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | sub post_content { | 
| 29 | 0 |  |  | 0 | 1 |  | my ($self, %args) = @_; | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | return { | 
| 32 | 0 | 0 |  |  |  |  | paste => 'Send', | 
|  |  | 0 |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | code2 => $args{text}, | 
| 34 |  |  |  |  |  |  | poster => exists($args{nick})? $args{nick} : '', | 
| 35 |  |  |  |  |  |  | format => exists($self->FORMATS->{$args{lang}})? $args{lang} : 'text', | 
| 36 |  |  |  |  |  |  | expiry => 'd' | 
| 37 |  |  |  |  |  |  | }; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub fill_form { | 
| 41 | 0 |  |  | 0 | 1 |  | my ($self, $mech) = (shift, shift); | 
| 42 | 0 |  |  |  |  |  | my %args = @_; | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 0 |  |  |  |  |  | my $header = { | 
| 45 |  |  |  |  |  |  | 'User-Agent' => 'Mozilla/5.0', | 
| 46 |  |  |  |  |  |  | 'Content-Type' => 'application/x-www-form-urlencoded' | 
| 47 |  |  |  |  |  |  | }; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 0 |  |  |  |  |  | my $content = $self->post_content(%args); | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 |  |  |  |  |  | $mech->agent_alias('Linux Mozilla'); | 
| 52 | 0 |  | 0 |  |  |  | my $form = $mech->form_name('editor') || return; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | # do not follow redirect please | 
| 55 | 0 |  |  |  |  |  | @{$mech->requests_redirectable} = (); | 
|  | 0 |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 0 |  |  |  |  |  | my $paste = HTML::Form::Input->new( | 
| 58 |  |  |  |  |  |  | type => 'text', | 
| 59 |  |  |  |  |  |  | value => 'Send', | 
| 60 |  |  |  |  |  |  | name => 'paste' | 
| 61 |  |  |  |  |  |  | )->add_to_form($form); | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 0 |  |  |  |  |  | return $mech->submit_form( form_name => 'editor', fields => $content ); | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | sub return { | 
| 67 | 0 |  |  | 0 | 1 |  | my ($self, $mech) = (shift, shift); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 0 | 0 | 0 |  |  |  | return unless blessed($mech->res) && $mech->res->can('header'); | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 0 | 0 |  |  |  |  | my $result  = $mech->res->header('Location')? 1 : 0; | 
| 72 | 0 | 0 |  |  |  |  | my $link_or_err = $result? $mech->res->header('Location') : 'Error!'; | 
| 73 |  |  |  |  |  |  |  | 
| 74 | 0 |  |  |  |  |  | return (1, $link_or_err); | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 | 1 |  |  |  |  | 165 | use constant FORMATS => { | 
| 78 |  |  |  |  |  |  | abap => 1, | 
| 79 |  |  |  |  |  |  | actionscript => 1, | 
| 80 |  |  |  |  |  |  | ada => 1, | 
| 81 |  |  |  |  |  |  | apache => 1, | 
| 82 |  |  |  |  |  |  | applescript => 1, | 
| 83 |  |  |  |  |  |  | asm => 1, | 
| 84 |  |  |  |  |  |  | asp => 1, | 
| 85 |  |  |  |  |  |  | autoit => 1, | 
| 86 |  |  |  |  |  |  | bash => 1, | 
| 87 |  |  |  |  |  |  | blitzbasic => 1, | 
| 88 |  |  |  |  |  |  | bnf => 1, | 
| 89 |  |  |  |  |  |  | c => 1, | 
| 90 |  |  |  |  |  |  | c_mac => 1, | 
| 91 |  |  |  |  |  |  | caddcl => 1, | 
| 92 |  |  |  |  |  |  | cadlisp => 1, | 
| 93 |  |  |  |  |  |  | cfm => 1, | 
| 94 |  |  |  |  |  |  | cpp => 1, | 
| 95 |  |  |  |  |  |  | csharp => 1, | 
| 96 |  |  |  |  |  |  | css => 1, | 
| 97 |  |  |  |  |  |  | d => 1, | 
| 98 |  |  |  |  |  |  | delphi => 1, | 
| 99 |  |  |  |  |  |  | diff => 1, | 
| 100 |  |  |  |  |  |  | dos => 1, | 
| 101 |  |  |  |  |  |  | eiffel => 1, | 
| 102 |  |  |  |  |  |  | erlang => 1, | 
| 103 |  |  |  |  |  |  | fortran => 1, | 
| 104 |  |  |  |  |  |  | freebasic => 1, | 
| 105 |  |  |  |  |  |  | genero => 1, | 
| 106 |  |  |  |  |  |  | gml => 1, | 
| 107 |  |  |  |  |  |  | groovy => 1, | 
| 108 |  |  |  |  |  |  | haskell => 1, | 
| 109 |  |  |  |  |  |  | html4strict => 1, | 
| 110 |  |  |  |  |  |  | idl => 1, | 
| 111 |  |  |  |  |  |  | ini => 1, | 
| 112 |  |  |  |  |  |  | inno => 1, | 
| 113 |  |  |  |  |  |  | java => 1, | 
| 114 |  |  |  |  |  |  | javascript => 1, | 
| 115 |  |  |  |  |  |  | latex => 1, | 
| 116 |  |  |  |  |  |  | lisp => 1, | 
| 117 |  |  |  |  |  |  | lsl2 => 1, | 
| 118 |  |  |  |  |  |  | lua => 1, | 
| 119 |  |  |  |  |  |  | m68k => 1, | 
| 120 |  |  |  |  |  |  | matlab => 1, | 
| 121 |  |  |  |  |  |  | mirc => 1, | 
| 122 |  |  |  |  |  |  | mpasm => 1, | 
| 123 |  |  |  |  |  |  | mysql => 1, | 
| 124 |  |  |  |  |  |  | nsis => 1, | 
| 125 |  |  |  |  |  |  | objc => 1, | 
| 126 |  |  |  |  |  |  | ocaml => 1, | 
| 127 |  |  |  |  |  |  | oobas => 1, | 
| 128 |  |  |  |  |  |  | oracle8 => 1, | 
| 129 |  |  |  |  |  |  | pascal => 1, | 
| 130 |  |  |  |  |  |  | perl => 1, | 
| 131 |  |  |  |  |  |  | php => 1, | 
| 132 |  |  |  |  |  |  | plswl => 1, | 
| 133 |  |  |  |  |  |  | python => 1, | 
| 134 |  |  |  |  |  |  | qbasic => 1, | 
| 135 |  |  |  |  |  |  | rails => 1, | 
| 136 |  |  |  |  |  |  | robots => 1, | 
| 137 |  |  |  |  |  |  | ruby => 1, | 
| 138 |  |  |  |  |  |  | scheme => 1, | 
| 139 |  |  |  |  |  |  | smalltalk => 1, | 
| 140 |  |  |  |  |  |  | smarty => 1, | 
| 141 |  |  |  |  |  |  | sql => 1, | 
| 142 |  |  |  |  |  |  | tcl => 1, | 
| 143 |  |  |  |  |  |  | text => 1, | 
| 144 |  |  |  |  |  |  | unreal => 1, | 
| 145 |  |  |  |  |  |  | vb => 1, | 
| 146 |  |  |  |  |  |  | vbnet => 1, | 
| 147 |  |  |  |  |  |  | visualfoxpro => 1, | 
| 148 |  |  |  |  |  |  | xml => 1, | 
| 149 |  |  |  |  |  |  | z80 => 1 | 
| 150 | 1 |  |  | 1 |  | 7 | }; | 
|  | 1 |  |  |  |  | 2 |  | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | 1; | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =head1 NAME | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | App::Nopaste::Service::AnyPastebin - paste to any pastebin that runs the same paste service as http://pastebin.com/ | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =head1 METHODS | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =head2 forbid_in_default | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | Constant of false | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =head2 post_content | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | Returns a HashRef of content to post. | 
| 167 |  |  |  |  |  |  | By default: | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | { | 
| 170 |  |  |  |  |  |  | paste => 'Send', | 
| 171 |  |  |  |  |  |  | code2 => 'text', | 
| 172 |  |  |  |  |  |  | poster => 'nick', | 
| 173 |  |  |  |  |  |  | format => 'lang', | 
| 174 |  |  |  |  |  |  | expiry => 'd' | 
| 175 |  |  |  |  |  |  | }; | 
| 176 |  |  |  |  |  |  |  | 
| 177 |  |  |  |  |  |  | Of course nothing is stopping you from building sub-classing this. | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | =cut | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | =head2 fill_form | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | Overwritten to submit paste via L | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | =head2 get | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | Overwritten to pack basic auth information into L | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | =head2 return | 
| 190 |  |  |  |  |  |  |  | 
| 191 |  |  |  |  |  |  | Parse redirect and return uri | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | =head2 uri | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | Default of http://pastebin.com | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | =cut | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | =head1 AUTHOR | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | Jason M Mills, C<<  >> | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | =head1 TODO | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | * Write more tests | 
| 206 |  |  |  |  |  |  | * Localize requests_redirectable deletion | 
| 207 |  |  |  |  |  |  | * Come up with a way to access basic auth with out using private accessors | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | =head1 BUGS | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | Please report any bugs or feature requests to C, or through | 
| 212 |  |  |  |  |  |  | the web interface at L.  I will be notified, and then you'll | 
| 213 |  |  |  |  |  |  | automatically be notified of progress on your bug as I make changes. | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | =head1 SUPPORT | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | perldoc App::Nopaste::Service::AnyPastebin | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  | You can also look for information at: | 
| 223 |  |  |  |  |  |  |  | 
| 224 |  |  |  |  |  |  | =over 4 | 
| 225 |  |  |  |  |  |  |  | 
| 226 |  |  |  |  |  |  | =item * RT: CPAN's request tracker | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | L | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | L | 
| 233 |  |  |  |  |  |  |  | 
| 234 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  | L | 
| 237 |  |  |  |  |  |  |  | 
| 238 |  |  |  |  |  |  | =item * Search CPAN | 
| 239 |  |  |  |  |  |  |  | 
| 240 |  |  |  |  |  |  | L | 
| 241 |  |  |  |  |  |  |  | 
| 242 |  |  |  |  |  |  | =item * GitHub | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | L | 
| 245 |  |  |  |  |  |  |  | 
| 246 |  |  |  |  |  |  | =back | 
| 247 |  |  |  |  |  |  |  | 
| 248 |  |  |  |  |  |  |  | 
| 249 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 250 |  |  |  |  |  |  |  | 
| 251 |  |  |  |  |  |  | L | 
| 252 |  |  |  |  |  |  |  | 
| 253 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 254 |  |  |  |  |  |  |  | 
| 255 |  |  |  |  |  |  | Copyright 2010 Jason M Mills. | 
| 256 |  |  |  |  |  |  |  | 
| 257 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 258 |  |  |  |  |  |  | under the terms of either: the GNU General Public License as published | 
| 259 |  |  |  |  |  |  | by the Free Software Foundation; or the Artistic License. | 
| 260 |  |  |  |  |  |  |  | 
| 261 |  |  |  |  |  |  | See http://dev.perl.org/licenses/ for more information. | 
| 262 |  |  |  |  |  |  |  | 
| 263 |  |  |  |  |  |  |  | 
| 264 |  |  |  |  |  |  | =cut |