blib/lib/Net/Azure/NotificationHubs.pm

filter: Statementstmt 100% 77 / 77 Branchbran 92.8% 13 / 14 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 100% 16 / 16 Podpod 100% 2 / 2 totaltotal 99.1% 121 / 122 CC 12 SCAR 9.9
CC
12
Cov
99%
_req
5.0
send
4.0
new
4.0
CRAP 2.7
↑ Summary blib/lib/Net/Azure/NotificationHubs/Response.pm »
1 package Net::Azure::NotificationHubs;
2 5 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Net::Azure::Authorization::SAS;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Net::Azure::NotificationHubs::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use String::CamelCase qw/camelize wordsplit/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 use Class::Accessor::Lite (
14 5 new => 0,
15 ro => [qw[
16 agent
17 serializer
18 api_version
19 authorizer
20 apns_expiry
21 hub_name
22 ]],
23 5 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 our $VERSION = "0.04";
26 5 our $DEFAULT_API_VERSION = "2015-04";
27 5 our $DEFAULT_TIMEOUT = 60;
28  
29 sub new {
30 9 ▶ my ($class, %param) = @_;
Subroutine new: called CC=4 SCAR=13.9
Pod documented
31
32 9 $param{agent} = HTTP::Tiny->new(agent => sprintf('%s/%s', $class, $VERSION));
33 9 $param{serializer} = JSON->new->utf8(1);
34 9 ▶ $param{api_version} ||= $DEFAULT_API_VERSION;
Condition100%3/3
$param{"api_version"} ||= $Net::Azure::NotificationHubs::DEFAULT_API_VERSION
l!l&&r!l&&!r
162
MC/DC100%2/2
$param{"api_version"} ||= $Net::Azure::NotificationHubs::DEFAULT_API_VERSION
$param{"api_version"} $Net::Azure::NotificationHubs::DEFAULT_API_VERSION
Truth table100%3/3
A ||= B
A= $param{"api_version"}B= $Net::Azure::NotificationHubs::DEFAULT_API_VERSION
ABresult
1X1
011
000
35  
36 9 ▶ if (!defined $param{authorizer}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $param{"authorizer"}) 8 1 9
37 8 $param{authorizer} = eval {
38 8 Net::Azure::Authorization::SAS->new(connection_string => $param{connection_string});
39 };
40 8 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 7 8
41 1 croak $@;
42 };
43 }
44  
45 8 bless {%param}, $class;
46 }
47  
48 sub _uri {
49 8 ▶ my ($self, $path, %params) = @_;
Subroutine _uri: called CC=2 SCAR=6.9
50 8 ▶ $path ||= '/';
Condition100%2/2
$path ||= "/"
l!l
71
MC/DC100%1/1
$path ||= "/"
$path
Truth table100%2/2
A
A= $path
Aresult
11
00
51 8 my $uri = URI->new($self->authorizer->endpoint);
52 8 $uri->scheme('https');
53 8 $uri->path($path);
54 8 $uri->query_form(%params);
55 8 $uri;
56 }
57  
58 sub _req {
59 8 ▶ my ($self, $path, $payload, %params) = @_;
Subroutine _req: called CC=5 SCAR=16.1
60 8 ▶ croak 'path is reuired' if !defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 1 7 8
61 7 ▶ croak 'payload is required' if !defined $payload;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $payload 1 6 7
62 6 ▶ croak 'payload is not hashref' if ref($payload) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $payload ne "HASH" 1 5 6
63 5 ▶ $params{api_version} ||= $self->api_version;
Condition100%3/3
$params{"api_version"} ||= $self->api_version
l!l&&r!l&&!r
131
MC/DC100%2/2
$params{"api_version"} ||= $self->api_version
$params{"api_version"} $self->api_version
Truth table100%3/3
A ||= B
A= $params{"api_version"}B= $self->api_version
ABresult
1X1
011
000
64 5 my $uri = $self->_uri($path, %params);
65 5 my $auth = $self->authorizer->token($uri->as_string);
66 5 my $data = $self->serializer->encode($payload);
67 5 my $req = Net::Azure::NotificationHubs::Request->new(
68 POST => $uri->as_string,
69 {
70 'Authorization' => $auth,
71 'Content-Type' => 'application/atom+xml;charset=utf-8',
72 },
73 $data,
74 );
75 5 $req->agent($self->agent);
76 5 $req;
77 }
78  
79 sub send {
80 2 ▶ my ($self, $payload, %param) = @_;
Subroutine send: called CC=4 SCAR=13.9
Pod documented
81 2 my $path = sprintf "/%s/messages/", $self->hub_name;
82 2 my $req = $self->_req($path, $payload);
83 2 for my $key (keys %param) {
84 3 ▶ next if !defined $param{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $param{$key} 0 3 3
85 3 my $header_name = join('-', 'ServiceBusNotification', wordsplit(camelize($key)));
86 3 $req->header($header_name => $param{$key});
87 }
88 2 ▶ if ($param{format} eq 'apple') {
Branch: 1 branch
BranchTrueFalseTotal
if ($param{"format"} eq "apple") 1 1 2
89 1 $req->header('ServiceBusNotification-Apns-Expiry' => $self->apns_expiry);
90 }
91 2 $req;
92 }
93  
94  
95 5 1;
96 __END__
↑ Summary blib/lib/Net/Azure/NotificationHubs/Response.pm »