line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Azure::EventHubs; |
2
|
5
|
|
|
5
|
|
273971
|
use 5.008001; |
|
5
|
|
|
|
|
59
|
|
3
|
5
|
|
|
5
|
|
27
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
106
|
|
4
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
129
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
2049
|
use Net::Azure::EventHubs::Request; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
211
|
|
7
|
5
|
|
|
5
|
|
2147
|
use Net::Azure::Authorization::SAS; |
|
5
|
|
|
|
|
31879
|
|
|
5
|
|
|
|
|
164
|
|
8
|
5
|
|
|
5
|
|
34
|
use JSON; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
29
|
|
9
|
5
|
|
|
5
|
|
3709
|
use LWP::UserAgent; |
|
5
|
|
|
|
|
85686
|
|
|
5
|
|
|
|
|
176
|
|
10
|
5
|
|
|
5
|
|
37
|
use URI; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
100
|
|
11
|
5
|
|
|
5
|
|
25
|
use Carp; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
276
|
|
12
|
5
|
|
|
5
|
|
65
|
use Try::Tiny; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
337
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
15
|
5
|
|
|
|
|
43
|
new => 0, |
16
|
|
|
|
|
|
|
ro => [qw[ |
17
|
|
|
|
|
|
|
agent |
18
|
|
|
|
|
|
|
timeout |
19
|
|
|
|
|
|
|
serializer |
20
|
|
|
|
|
|
|
api_version |
21
|
|
|
|
|
|
|
authorizer |
22
|
|
|
|
|
|
|
]], |
23
|
5
|
|
|
5
|
|
55
|
); |
|
5
|
|
|
|
|
11
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = "0.09"; |
26
|
|
|
|
|
|
|
our $DEFAULT_API_VERSION = '2014-01'; |
27
|
|
|
|
|
|
|
our $DEFAULT_TIMEOUT = 60; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
9
|
|
|
9
|
1
|
23746
|
my ($class, %param) = @_; |
31
|
|
|
|
|
|
|
|
32
|
9
|
|
|
|
|
85
|
$param{agent} = LWP::UserAgent->new(agent => sprintf('%s/%s', $class, $VERSION)); |
33
|
9
|
|
|
|
|
12891
|
$param{serializer} = JSON->new->utf8(1); |
34
|
9
|
|
100
|
|
|
67
|
$param{api_version} ||= $DEFAULT_API_VERSION; |
35
|
9
|
|
100
|
|
|
45
|
$param{timeout} ||= $DEFAULT_TIMEOUT; |
36
|
|
|
|
|
|
|
|
37
|
9
|
100
|
|
|
|
34
|
if (!defined $param{authorizer}) { |
38
|
|
|
|
|
|
|
my $authorizer = try { |
39
|
|
|
|
|
|
|
Net::Azure::Authorization::SAS->new(connection_string => $param{connection_string}) |
40
|
8
|
|
|
8
|
|
775
|
} catch { |
41
|
1
|
|
|
1
|
|
455
|
croak $_; |
42
|
8
|
|
|
|
|
65
|
}; |
43
|
7
|
|
|
|
|
1585
|
$param{authorizer} = $authorizer; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
8
|
|
|
|
|
99
|
bless {%param}, $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _uri { |
50
|
7
|
|
|
7
|
|
11090
|
my ($self, $path, %params) = @_; |
51
|
7
|
|
100
|
|
|
23
|
$path ||= '/'; |
52
|
7
|
|
|
|
|
25
|
my $uri = URI->new($self->authorizer->endpoint); |
53
|
7
|
|
|
|
|
17281
|
$uri->scheme('https'); |
54
|
7
|
|
|
|
|
11640
|
$uri->path($path); |
55
|
7
|
|
|
|
|
297
|
$uri->query_form(%params); |
56
|
7
|
|
|
|
|
507
|
$uri; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _req { |
60
|
7
|
|
|
7
|
|
18067
|
my ($self, $path, $payload, %params) = @_; |
61
|
7
|
100
|
|
|
|
43
|
croak 'path is reuired' if !defined $path; |
62
|
6
|
100
|
|
|
|
26
|
croak 'payload is required' if !defined $payload; |
63
|
5
|
100
|
|
|
|
26
|
croak 'payload is not hashref' if ref($payload) ne 'HASH'; |
64
|
4
|
|
100
|
|
|
29
|
$params{timeout} ||= $self->timeout; |
65
|
4
|
|
100
|
|
|
57
|
$params{api_version} ||= $self->api_version; |
66
|
4
|
|
|
|
|
35
|
my $uri = $self->_uri($path, %params); |
67
|
4
|
|
|
|
|
17
|
my $auth = $self->authorizer->token($uri->as_string); |
68
|
4
|
|
|
|
|
1175
|
my $data = $self->serializer->encode($payload); |
69
|
4
|
|
|
|
|
95
|
my $req = Net::Azure::EventHubs::Request->new( |
70
|
|
|
|
|
|
|
POST => $uri->as_string, |
71
|
|
|
|
|
|
|
[ |
72
|
|
|
|
|
|
|
'Authorization' => $auth, |
73
|
|
|
|
|
|
|
'Content-Type' => 'application/atom+xml;type=entry;charset=utf-8', |
74
|
|
|
|
|
|
|
], |
75
|
|
|
|
|
|
|
$data, |
76
|
|
|
|
|
|
|
); |
77
|
4
|
|
|
|
|
958
|
$req->agent($self->agent); |
78
|
4
|
|
|
|
|
62
|
$req; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub message { |
82
|
1
|
|
|
1
|
1
|
1472
|
my ($self, $payload) = @_; |
83
|
1
|
|
|
|
|
5
|
my $path = sprintf "/%s/messages", $self->authorizer->{entity_path}; |
84
|
1
|
|
|
|
|
18
|
my $req = $self->_req($path => $payload); |
85
|
1
|
|
|
|
|
3
|
$req; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |