| 1 | package WWW::Pastebin::Base::Retrieve; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use base 'Class::Data::Accessor'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | __PACKAGE__->mk_classaccessors( qw( | |||||||||||||||||||||||||||
| 14 | ua | ||||||||||||||||||||||||||||
| 15 | uri | ||||||||||||||||||||||||||||
| 16 | id | ||||||||||||||||||||||||||||
| 17 | content | ||||||||||||||||||||||||||||
| 18 | error | ||||||||||||||||||||||||||||
| 19 | results | ||||||||||||||||||||||||||||
| 20 | )); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | use overload q|""| => sub { shift->content }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 26 | 1 | ▶ | croak "Must have even number of arguments to new()" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | if @_ & 1; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | my %args = @_; | |||||||||||||||||||||||||||
| 30 | 1 | $args{ +lc } = delete $args{ $_ } for keys %args; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | $args{timeout} ||= 30; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"timeout"} ||= 30
MC/DC0%0/1
$args{"timeout"} ||= 30
$args{"timeout"}
Truth table50%1/2
A
A= $args{"timeout"}
| |||||||||||||||||||||||||||||
| 33 | $args{ua} ||= LWP::UserAgent->new( | ||||||||||||||||||||||||||||
| 34 | timeout => $args{timeout}, | ||||||||||||||||||||||||||||
| 35 | 1 | ▶ | agent => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12)' | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"ua"} ||= "LWP::UserAgent"->new("timeout", $args{"timeout"}, "agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12) Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12")
MC/DC0%0/2
$args{"ua"} ||= "LWP::UserAgent"->new("timeout", $args{"timeout"}, "agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12) Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12")
$args{"ua"}
"LWP::UserAgent"->new("timeout", $args{"timeout"}, "agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12) Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12")
Truth table33%1/3
A ||= B
A= $args{"ua"}B= "LWP::UserAgent"->new("timeout", $args{"timeout"}, "agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.12) Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12")
| |||||||||||||||||||||||||||||
| 36 | .' Gecko/20080207 Ubuntu/7.10 (gutsy) Firefox/2.0.0.12', | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 40 | 1 | $self->ua( $args{ua} ); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | return $self; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub retrieve { | ||||||||||||||||||||||||||
|
Subroutine
retrieve: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | 0 | my $id = shift; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 0 | $self->$_(undef) for qw(error uri id results); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return $self->_set_error('Missing or empty paste ID or URI') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $id and length $id
MC/DC0%0/2
defined $id and length $id
defined $id
length $id
Truth table0%0/3
A and B
A= defined $idB= length $id
| |||||||||||||||||||||||||||||
| 52 | unless defined $id and length $id; | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | ( my $uri, $id ) = $self->_make_uri_and_id( $id, @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | or return; | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | $self->id( $id ); | |||||||||||||||||||||||||||
| 58 | 0 | $self->uri( $uri ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | my $ua = $self->ua; | |||||||||||||||||||||||||||
| 61 | 0 | my $response = $ua->get( $uri ); | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( $response->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | return $self->_get_was_successful( $response->content ); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | else { | ||||||||||||||||||||||||||||
| 66 | 0 | return $self->_set_error('Network error: ' . $response->status_line); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub _get_was_successful { | ||||||||||||||||||||||||||
|
Subroutine
_get_was_successful: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 71 | 0 | my ( $self, $content ) = @_; | |||||||||||||||||||||||||||
| 72 | 0 | return $self->results( $self->_parse( $content ) ); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub _set_error { | ||||||||||||||||||||||||||
|
Subroutine
_set_error: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 76 | 0 | my ( $self, $error_or_response_obj, $is_net_error ) = @_; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( defined $is_net_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | $self->error( 'Network error: ' . $error_or_response_obj->status_line | |||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | else { | ||||||||||||||||||||||||||||
| 82 | 0 | $self->error( $error_or_response_obj ); | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | 0 | return; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub _parse { | ||||||||||||||||||||||||||
|
Subroutine
_parse: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 88 | 0 | croak "Looks like the author of the module forgot to override the" | |||||||||||||||||||||||||||
| 89 | . "_parse() methods"; | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _make_uri_and_id { | ||||||||||||||||||||||||||
|
Subroutine
_make_uri_and_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 93 | 0 | croak "Looks like the author of the module forgot to override the" | |||||||||||||||||||||||||||
| 94 | . "_make_uri_and_id() methods"; | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | 1; | |||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||