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

filter: Statementstmt 80.8% 38 / 47 Branchbran 40.0% 4 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 74.3% 61 / 82 CC 8 SCAR 14.3
CC
8
Cov
73%
build_request
12.2
new
4.1
send
2.5
CRAP 4.2
« Build ↑ Summary blib/lib/WWW/Google/Cloud/Messaging/Response/Result.pm »
1 package WWW::Google::Cloud::Messaging;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use JSON qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 use Class::Accessor::Lite (
12 4 new => 0,
13 rw => [qw/ua api_url api_key/],
14 4 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use WWW::Google::Cloud::Messaging::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 our $VERSION = '0.05';
19  
20 4 our $API_URL = 'https://android.googleapis.com/gcm/send';
21  
22 sub new {
23 5 ▶ my ($class, %args) = @_;
Subroutine new: called CC=4 SCAR=14.0
Pod documented
24 5 ▶ 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 4 5
25  
26 4 ▶ $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
130
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 4 ▶ $args{api_url} ||= $API_URL;
Condition66%2/3
$args{"api_url"} ||= $WWW::Google::Cloud::Messaging::API_URL
l!l&&r!l&&!r
130
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 4 bless { %args }, $class;
30 }
31  
32 sub send {
33 1 ▶ my ($self, $payload) = @_;
Subroutine send: called CC=2 SCAR=9.2
Pod documented
34 1 ▶ croak 'Usage: $gcm->send(\%payload)' unless ref $payload eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload eq "HASH" 1 0 1
35  
36 0 my $res = $self->ua->request($self->build_request($payload));
37 0 return WWW::Google::Cloud::Messaging::Response->new($res);
38 }
39  
40 sub build_request {
41 1 ▶ my ($self, $payload) = @_;
Subroutine build_request: called CC=4 SCAR=25.0
Pod documented
42 1 ▶ croak 'Usage: $gcm->build_request(\%payload)' unless ref $payload eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload eq "HASH" 1 0 1
43  
44 0 ▶ if (exists $payload->{delay_while_idle}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $payload->{"delay_while_idle"}) 0 0 0
45 0 ▶ $payload->{delay_while_idle} = $payload->{delay_while_idle} ? JSON::true : JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$payload->{'delay_while_idle'} ? : 0 0 0
46 }
47  
48 0 my $req = HTTP::Request->new(POST => $self->api_url);
49 0 $req->header(Authorization => 'key='.$self->api_key);
50 0 $req->header('Content-Type' => 'application/json; charset=UTF-8');
51 0 $req->content(encode_json $payload);
52 0 return $req;
53 }
54  
55 4 1;
56 __END__
« Build ↑ Summary blib/lib/WWW/Google/Cloud/Messaging/Response/Result.pm »