blib/lib/WWW/Google/Cloud/Messaging.pm

filter: Statementstmt 81.8% 36 / 44 Branchbran 37.5% 3 / 8 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 74.6% 56 / 75 CC 7 SCAR 14.9
CC
7
Cov
74%
send
12.6
new
4.1
BEGIN
1.0
CRAP 4.4
↑ Summary Build »
1 package WWW::Google::Cloud::Messaging;
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 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use JSON qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 use Class::Accessor::Lite (
12 3 new => 0,
13 rw => [qw/ua api_url api_key/],
14 3 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use WWW::Google::Cloud::Messaging::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 our $VERSION = '0.04';
19  
20 3 our $API_URL = 'https://android.googleapis.com/gcm/send';
21  
22 sub new {
23 4 ▶ my ($class, %args) = @_;
Subroutine new: called CC=4 SCAR=14.0
Pod documented
24 4 ▶ croak 'Usage: WWW::Google::Cloud::Messaging->new(api_key => $api_key)' unless defined $args{api_key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"api_key"} 1 3 4
25  
26 3 ▶ $args{ua} ||= LWP::UserAgent->new(agent => __PACKAGE__.'/'.$VERSION);
Condition66%2/3
$args{"ua"} ||= "LWP::UserAgent"->new("agent", 'WWW::Google::Cloud::Messaging/' . $WWW::Google::Cloud::Messaging::VERSION)
l!l&&r!l&&!r
120
MC/DC0%0/2
$args{"ua"} ||= "LWP::UserAgent"->new("agent", 'WWW::Google::Cloud::Messaging/' . $WWW::Google::Cloud::Messaging::VERSION)
$args{"ua"} "LWP::UserAgent"->new("agent", 'WWW::Google::Cloud::Messaging/' . $WWW::Google::Cloud::Messaging::VERSION)
Truth table66%2/3
A ||= B
A= $args{"ua"}B= "LWP::UserAgent"->new("agent", 'WWW::Google::Cloud::Messaging/' . $WWW::Google::Cloud::Messaging::VERSION)
ABresult
1X1
011
000
27 3 ▶ $args{api_url} ||= $API_URL;
Condition66%2/3
$args{"api_url"} ||= $WWW::Google::Cloud::Messaging::API_URL
l!l&&r!l&&!r
120
MC/DC0%0/2
$args{"api_url"} ||= $WWW::Google::Cloud::Messaging::API_URL
$args{"api_url"} $WWW::Google::Cloud::Messaging::API_URL
Truth table66%2/3
A ||= B
A= $args{"api_url"}B= $WWW::Google::Cloud::Messaging::API_URL
ABresult
1X1
011
000
28  
29 3 bless { %args }, $class;
30 }
31  
32 sub send {
33 1 ▶ my ($self, $payload) = @_;
Subroutine send: called CC=4 SCAR=25.3
Pod documented
34 1 ▶ croak 'Usage: $gcm->send(\%payload)' unless ref $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload 1 0 1
35  
36 0 ▶ if (exists $payload->{delay_while_idle}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $payload->{"delay_while_idle"}) 0 0 0
37 0 ▶ $payload->{delay_while_idle} = $payload->{delay_while_idle} ? JSON::true : JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$payload->{'delay_while_idle'} ? : 0 0 0
38 }
39  
40 0 my $req = HTTP::Request->new(POST => $self->api_url);
41 0 $req->header(Authorization => 'key='.$self->api_key);
42 0 $req->header('Content-Type' => 'application/json; charset=UTF-8');
43 0 $req->content(encode_json $payload);
44  
45 0 my $res = $self->ua->request($req);
46 0 return WWW::Google::Cloud::Messaging::Response->new($res);
47 }
48  
49 3 1;
50 __END__
↑ Summary Build »