NotificationHubs.pm

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