HTTP.pm

filter: Statementstmt 100% 50 / 50 Branchbran 87.5% 7 / 8 Conditioncond 83.3% 10 / 12 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 13 / 13 Podpod 66.6% 2 / 3 totaltotal 91.4% 86 / 94 CC 9 SCAR 11.6
CC
9
Cov
96%
new
7.0
build_request
2.0
send
2.0
CRAP 3.2
↑ Summary HTTP/Response.pm »
1 package WWW::FCM::HTTP;
2 3 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
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  
6 3 our $VERSION = "0.03";
7  
8 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use LWP::Protocol::https;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use LWP::ConnCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use JSON qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Class::Accessor::Lite (
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 new => 0,
14 rw => [qw/ua api_url api_key json/],
15 3 );
16 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use WWW::FCM::HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 our $API_URL = 'https://fcm.googleapis.com/fcm/send';
21  
22 15 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
23 15 my $class = shift;
24 15 ▶ my %args = $_[0] && ref $_[0] eq 'HASH' ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] && ref $_[0] eq 'HASH' ? : 1 14 15
Condition100%3/3
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
1131
MC/DC100%2/2
$_[0] and ref $_[0] eq "HASH"
$_[0] ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
25 croak 'Usage: WWW::FCM::HTTP->new({ api_key => $api_key })'
26 15 ▶ unless (exists $args{api_key} && defined $args{api_key});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"api_key"} and defined $args{"api_key"} 2 13 15
Condition100%3/3
exists $args{"api_key"} and defined $args{"api_key"}
!ll&&!rl&&r
1113
MC/DC100%2/2
exists $args{"api_key"} and defined $args{"api_key"}
exists $args{"api_key"} defined $args{"api_key"}
Truth table100%3/3
A and B
A= exists $args{"api_key"}B= defined $args{"api_key"}
ABresult
0X0
100
111
27  
28 13 ▶ $args{api_url} ||= $API_URL;
Condition66%2/3
$args{"api_url"} ||= $WWW::FCM::HTTP::API_URL
l!l&&r!l&&!r
1120
MC/DC0%0/2
$args{"api_url"} ||= $WWW::FCM::HTTP::API_URL
$args{"api_url"} $WWW::FCM::HTTP::API_URL
Truth table66%2/3
A ||= B
A= $args{"api_url"}B= $WWW::FCM::HTTP::API_URL
ABresult
1X1
011
000
29 13 ▶ $args{ua} ||= LWP::UserAgent->new(
Condition66%2/3
$args{"ua"} ||= "LWP::UserAgent"->new("agent", 'WWW::FCM::HTTP/' . $WWW::FCM::HTTP::VERSION, "conn_cache", "LWP::ConnCache"->new)
l!l&&r!l&&!r
1120
MC/DC0%0/2
$args{"ua"} ||= "LWP::UserAgent"->new("agent", 'WWW::FCM::HTTP/' . $WWW::FCM::HTTP::VERSION, "conn_cache", "LWP::ConnCache"->new)
$args{"ua"} "LWP::UserAgent"->new("agent", 'WWW::FCM::HTTP/' . $WWW::FCM::HTTP::VERSION, "conn_cache", "LWP::ConnCache"->new)
Truth table66%2/3
A ||= B
A= $args{"ua"}B= "LWP::UserAgent"->new("agent", 'WWW::FCM::HTTP/' . $WWW::FCM::HTTP::VERSION, "conn_cache", "LWP::ConnCache"->new)
ABresult
1X1
011
000
30 agent => __PACKAGE__.'/'.$VERSION,
31 conn_cache => LWP::ConnCache->new,
32 );
33  
34 13 bless { %args }, $class;
35 }
36  
37 10 ▶sub send {
Subroutine send: called CC=2 SCAR=6.9
Pod documented
38 10 my ($self, $payload) = @_;
39 10 ▶ croak 'Usage: $fcm->send(\%payload)' unless ref $payload eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload eq "HASH" 4 6 10
40  
41 6 my $res = $self->ua->request($self->build_request($payload));
42 6 WWW::FCM::HTTP::Response->new($res, $payload->{registration_ids});
43 }
44  
45 6 ▶sub build_request {
Subroutine build_request: called CC=2 SCAR=7.0
Pod undocumented
46 6 my ($self, $payload) = @_;
47 6 ▶ croak 'Usage: $gcm->build_request(\%payload)' unless ref $payload eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload eq "HASH" 0 6 6
48  
49 6 my $req = HTTP::Request->new(POST => $self->api_url);
50 6 $req->header(Authorization => 'key='.$self->api_key);
51 6 $req->header('Content-Type' => 'application/json; charset=UTF-8');
52 6 $req->content(encode_json $payload);
53  
54 6 return $req;
55 }
56  
57 3 1;
58 __END__
↑ Summary HTTP/Response.pm »