blib/lib/WWW/Pastebin/Base/Retrieve.pm

filter: Statementstmt 60.0% 33 / 55 Branchbran 10.0% 1 / 10 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 57.1% 8 / 14 Podpod 0.0% 0 / 2 totaltotal 46.8% 44 / 94 CC 11 SCAR 25.4
CC
11
Cov
49%
retrieve
42.0
_set_error
6.0
new
5.4
CRAP 12.7
↑ Summary Build »
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.002';
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 2 ▶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 sub new {
25 1 ▶ my $class = shift;
Subroutine new: called CC=5 SCAR=16.8
Pod undocumented
26 1 ▶ croak "Must have even number of arguments to new()"
Branch: 1 branch
BranchTrueFalseTotal
if @_ & 1 0 1 1
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
l!l
01
MC/DC0%0/1
$args{"timeout"} ||= 30
$args{"timeout"}
Truth table50%1/2
A
A= $args{"timeout"}
Aresult
11
00
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")
l!l&&r!l&&!r
010
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")
ABresult
1X1
011
000
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 sub retrieve {
46 0 ▶ my $self = shift;
Subroutine retrieve: not called CC=6 SCAR=37.4
Pod undocumented
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
BranchTrueFalseTotal
unless defined $id and length $id 0 0 0
Condition0%0/3
defined $id and length $id
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
52 unless defined $id and length $id;
53  
54 0 ▶ ( my $uri, $id ) = $self->_make_uri_and_id( $id, @_ )
Branch: 1 branch
BranchTrueFalseTotal
(my $uri, $id) = $self->_make_uri_and_id($id, @_) or return 0 0 0
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
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
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 sub _get_was_successful {
71 0 ▶ my ( $self, $content ) = @_;
Subroutine _get_was_successful: not called CC=1 SCAR=6.9
72 0 return $self->results( $self->_parse( $content ) );
73 }
74  
75 sub _set_error {
76 0 ▶ my ( $self, $error_or_response_obj, $is_net_error ) = @_;
Subroutine _set_error: not called CC=2 SCAR=17.9
77 0 ▶ if ( defined $is_net_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $is_net_error) { } 0 0 0
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 sub _parse {
88 0 ▶ croak "Looks like the author of the module forgot to override the"
Subroutine _parse: not called CC=1 SCAR=6.9
89 . "_parse() methods";
90 }
91  
92 sub _make_uri_and_id {
93 0 ▶ croak "Looks like the author of the module forgot to override the"
Subroutine _make_uri_and_id: not called CC=1 SCAR=6.9
94 . "_make_uri_and_id() methods";
95 }
96  
97 2 1;
98 __END__
↑ Summary Build »