C2DM.pm

filter: Statementstmt 63.7% 37 / 58 Branchbran 35.7% 5 / 14 Conditioncond 50.0% 6 / 12 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 59.6% 62 / 104 CC 12 SCAR 29.9
CC
12
Cov
57%
send
50.4
new
5.0
BEGIN
1.0
CRAP 19.9
↑ Summary C2DM/Response.pm »
1 package WWW::Google::C2DM;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use LWP::Protocol::https;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use WWW::Google::C2DM::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 our $VERSION = '0.08';
15  
16 3 our $URL = 'https://android.apis.google.com/c2dm/send';
17  
18 4 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod documented
19 4 my ($class, %args) = @_;
20 4 ▶ croak "Usage: $class->new(auth_token => \$auth_token)" unless $args{auth_token};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"auth_token"} 1 3 4
21 3 ▶ $args{ua} ||= LWP::UserAgent->new(agent => __PACKAGE__.' / '.$VERSION);
Condition66%2/3
$args{"ua"} ||= "LWP::UserAgent"->new("agent", 'WWW::Google::C2DM / ' . $WWW::Google::C2DM::VERSION)
l!l&&r!l&&!r
120
MC/DC0%0/2
$args{"ua"} ||= "LWP::UserAgent"->new("agent", 'WWW::Google::C2DM / ' . $WWW::Google::C2DM::VERSION)
$args{"ua"} "LWP::UserAgent"->new("agent", 'WWW::Google::C2DM / ' . $WWW::Google::C2DM::VERSION)
Truth table66%2/3
A ||= B
A= $args{"ua"}B= "LWP::UserAgent"->new("agent", 'WWW::Google::C2DM / ' . $WWW::Google::C2DM::VERSION)
ABresult
1X1
011
000
22 3 ▶ if ($args{ua}->isa('LWP::UserAgent') && $LWP::UserAgent::VERSION >= 6.00) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"ua"}->isa("LWP::UserAgent") and $LWP::UserAgent::VERSION >= 6) 2 1 3
Condition66%2/3
$args{"ua"}->isa("LWP::UserAgent") and $LWP::UserAgent::VERSION >= 6
!ll&&!rl&&r
102
MC/DC50%1/2
$args{"ua"}->isa("LWP::UserAgent") and $LWP::UserAgent::VERSION >= 6
$args{"ua"}->isa("LWP::UserAgent") $LWP::UserAgent::VERSION >= 6
Truth table66%2/3
A and B
A= $args{"ua"}->isa("LWP::UserAgent")B= $LWP::UserAgent::VERSION >= 6
ABresult
0X0
100
111
23 2 $args{ua}->ssl_opts(verify_hostname => 0);
24 }
25 3 bless { %args }, $class;
26 }
27  
28 1 ▶sub send {
Subroutine send: called CC=8 SCAR=39.2
Pod documented
29 1 my ($self, %args) = @_;
30 croak 'Usage: $self->send(registration_id => $reg_id, collapse_key => $collapse_key)'
31 1 ▶ unless $args{registration_id} && defined $args{collapse_key} && length $args{collapse_key};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"registration_id"} and defined $args{"collapse_key"} and length $args{"collapse_key"} 1 0 1
Condition33%2/6
$args{"registration_id"} and defined $args{"collapse_key"} and length $args{"collapse_key"}
!ll&&!rl&&r
100
$args{"registration_id"} and defined $args{"collapse_key"}
!ll&&!rl&&r
100
MC/DC0%0/3
$args{"registration_id"} and defined $args{"collapse_key"} and length $args{"collapse_key"}
$args{"registration_id"} defined $args{"collapse_key"} length $args{"collapse_key"}
Truth table25%1/4
A and B and C
A= $args{"registration_id"}B= defined $args{"collapse_key"}C= length $args{"collapse_key"}
ABCresult
0XX0
10X0
1100
1111
32  
33 0 ▶ if (my $data = delete $args{data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $data = delete $args{"data"}) 0 0 0
34 0 ▶ croak 'data parameter must be HASHREF' unless ref $data eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 0 0
35 0 map { $args{"data.$_"} = $data->{$_} } keys %$data;
36 }
37  
38 0 my $req = HTTP::Request->new(POST => $URL);
39 0 $req->header('Content-Type' => 'application/x-www-form-urlencoded');
40 0 $req->header(Authorization => 'GoogleLogin auth='.$self->{auth_token});
41  
42 0 my $uri = URI->new('http://');
43 0 $uri->query_form(\%args);
44 0 $req->content($uri->query);
45  
46 0 my $http_response = $self->{ua}->request($req);
47  
48 0 my $result;
49 0 ▶ if ($http_response->code == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($http_response->code == 200) { } 0 0 0
50 0 my $content = $http_response->content;
51 0 my $params = { map { split '=', $_, 2 } split /\n/, $content };
52 0 ▶ if ($params->{Error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'Error'}) { } 0 0 0
53 $result = WWW::Google::C2DM::Response->new(
54 is_success => 0,
55 error_code => $params->{Error},
56 0 http_response => $http_response,
57 );
58 }
59 else {
60 0 $result = WWW::Google::C2DM::Response->new(
61 is_success => 1,
62 http_response => $http_response,
63 params => $params,
64 );
65 }
66 }
67 else {
68 0 $result = WWW::Google::C2DM::Response->new(
69 is_success => 0,
70 http_response => $http_response,
71 );
72 }
73  
74 0 return $result;
75 }
76  
77 3 1;
78 __END__
↑ Summary C2DM/Response.pm »