| 1 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 2 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | package App::Nopaste::Service; | ||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: base class for nopaste services | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 11 | our $VERSION = '1.013'; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use WWW::Mechanize; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub available { 1 } | ||||||||||||||||||||||||||||||
|
Subroutine
available: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub forbid_in_default { 0 } | ||||||||||||||||||||||||||||||
|
Subroutine
forbid_in_default: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | # this wrapper is so we can canonicalize arguments, especially "lang" | ||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | sub nopaste { | ||||||||||||||||||||||||||||||
|
Subroutine
nopaste: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 15 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||
| 16 | 2 | $self->run(@_); | |||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | sub run { | ||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 20 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 21 | 1 | my $mech = WWW::Mechanize->new; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 1 | $self->get($mech => @_); | |||||||||||||||||||||||||||||||
| 24 | 1 | $self->fill_form($mech => @_); | |||||||||||||||||||||||||||||||
| 25 | 1 | return $self->return($mech => @_); | |||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub uri { | ||||||||||||||||||||||||||||||
|
Subroutine
uri: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | my $class = ref($_[0]) || $_[0]; | ||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] || $_[0]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||||||
| 30 | 1 | Carp::croak "$class must provide a 'uri' method."; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub get { | ||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 34 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 35 | 1 | my $mech = shift; | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 1 | my $res = $mech->get($self->uri); | |||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | die "Unable to fetch ".$self->uri.": " . $res->status_line | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | unless $res->is_success; | ||||||||||||||||||||||||||||||||
| 40 | 1 | return $res; | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub fill_form { | ||||||||||||||||||||||||||||||
|
Subroutine
fill_form: called CC=6 SCAR=19.4
Pod
documented
| |||||||||||||||||||||||||||||||||
| 44 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 45 | 1 | my $mech = shift; | |||||||||||||||||||||||||||||||
| 46 | 1 | my %args = @_; | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 1 | $mech->form_number(1); | |||||||||||||||||||||||||||||||
| 49 | 1 | $args{chan} = $self->canonicalize_chan($mech, $args{chan}); | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | $mech->submit_form( | ||||||||||||||||||||||||||||||||
| 52 | fields => { | ||||||||||||||||||||||||||||||||
| 53 | paste => $args{text}, | ||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | do { $args{chan} ? (channel => $args{chan}) : () }, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | do { $args{desc} ? (summary => $args{desc}) : () }, | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | do { $args{nick} ? (nick => $args{nick}) : () }, | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
exists $args{"private"} and $args{"private"}
MC/DC0%0/2
exists $args{"private"} and $args{"private"}
exists $args{"private"}
$args{"private"}
Truth table33%1/3
A and B
A= exists $args{"private"}B= $args{"private"}
| |||||||||||||||||||||||||||||||||
| 57 | 1 | private => (exists $args{private} && $args{private} ? 1 : 0), | |||||||||||||||||||||||||||||||
| 58 | }, | ||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub canonicalize_chan { | ||||||||||||||||||||||||||||||
|
Subroutine
canonicalize_chan: called CC=5 SCAR=28.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 63 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 64 | 1 | my $mech = shift; | |||||||||||||||||||||||||||||||
| 65 | 1 | my $chan = shift; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | return $chan if !$chan; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | 0 | my @chans = grep { length } | |||||||||||||||||||||||||||||||
| 70 | $mech->current_form->find_input('channel')->possible_values; | ||||||||||||||||||||||||||||||||
| 71 | 0 | my %is_valid = map { $_ => 1 } @chans; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return $chan if $is_valid{$chan}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 0 | my $orig = $chan; | |||||||||||||||||||||||||||||||
| 76 | 0 | $chan =~ s/^\#//; | |||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | return $chan if $is_valid{$chan}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 0 | $chan = "#$chan"; | |||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | return $chan if $is_valid{$chan}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | 0 | warn "Invalid channel '$orig'. Valid values are: " . join(', ', @chans); | |||||||||||||||||||||||||||||||
| 83 | 0 | return $orig; | |||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | sub return { | ||||||||||||||||||||||||||||||
|
Subroutine
return: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 87 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||
| 88 | 1 | my $mech = shift; | |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | 1 | my $link = $mech->find_link(url_regex => qr{/?(?:\d+)$}); | |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | return (0, "Could not find paste link.") if !$link; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 93 | 1 | return (1, $link->url); | |||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | 11 | 1; | |||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||||||