Code/Role/Fetchable.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 94.5% 35 / 37 CC 3 SCAR 4.1
CC
3
Cov
93%
fetch
2.0
mech
2.0
BEGIN
1.0
CRAP 1.5
« Code/DateTime.pm ↑ Summary Code/Role/URL.pm »
1 package Net::Google::Code::Role::Fetchable;
2 12 ▶use Any::Moose 'Role';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use Params::Validate ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 12 our $MECH;
7  
8 11 ▶sub mech {
Subroutine mech: called CC=2 SCAR=6.9
Pod documented
9 11 ▶ if (!$MECH) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Net::Google::Code::Role::Fetchable::MECH) 4 7 11
10 4 $MECH = WWW::Mechanize->new(
11 agent => 'Net-Google-Code',
12 keep_alive => 4,
13 cookie_jar => {},
14 stack_depth => 1,
15 timeout => 60,
16 );
17 }
18 11 return $MECH ;
19 }
20  
21 1 ▶sub fetch {
Subroutine fetch: called CC=2 SCAR=7.1
Pod documented
22 1 my $self = shift;
23 1 my ($url) = validate_pos( @_, { type => SCALAR } );
24 1 $self->mech->get($url);
25 1 ▶ if ( !$self->mech->response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->mech->response->is_success) { } 0 1 1
26 0 die "Server threw an error "
27 . $self->mech->response->status_line . " for "
28 . $url;
29 }
30 else {
31 1 my $content = $self->mech->content;
32 # auto decode the content to erase HTML::Parser's utf8 warning like this:
33 # Parsing of undecoded UTF-8 will give garbage when decoding entities
34 1 utf8::downgrade( $content, 1 );
35 1 return $content;
36 }
37 }
38  
39 12 ▶no Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 12 1;
42  
43 __END__
« Code/DateTime.pm ↑ Summary Code/Role/URL.pm »