line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Azure::EventHubs; |
2
|
5
|
|
|
5
|
|
233464
|
use 5.008001; |
|
5
|
|
|
|
|
54
|
|
3
|
5
|
|
|
5
|
|
22
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
81
|
|
4
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
122
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
1737
|
use Net::Azure::EventHubs::Request; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
183
|
|
7
|
5
|
|
|
5
|
|
1867
|
use Net::Azure::Authorization::SAS; |
|
5
|
|
|
|
|
27571
|
|
|
5
|
|
|
|
|
154
|
|
8
|
5
|
|
|
5
|
|
31
|
use JSON; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
30
|
|
9
|
5
|
|
|
5
|
|
3317
|
use LWP::UserAgent; |
|
5
|
|
|
|
|
73254
|
|
|
5
|
|
|
|
|
175
|
|
10
|
5
|
|
|
5
|
|
43
|
use URI; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
84
|
|
11
|
5
|
|
|
5
|
|
21
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
331
|
|
12
|
5
|
|
|
5
|
|
27
|
use Try::Tiny; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
293
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
15
|
5
|
|
|
|
|
48
|
new => 0, |
16
|
|
|
|
|
|
|
ro => [qw[ |
17
|
|
|
|
|
|
|
agent |
18
|
|
|
|
|
|
|
timeout |
19
|
|
|
|
|
|
|
serializer |
20
|
|
|
|
|
|
|
api_version |
21
|
|
|
|
|
|
|
authorizer |
22
|
|
|
|
|
|
|
]], |
23
|
5
|
|
|
5
|
|
46
|
); |
|
5
|
|
|
|
|
18
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = "0.08"; |
26
|
|
|
|
|
|
|
our $DEFAULT_API_VERSION = '2014-01'; |
27
|
|
|
|
|
|
|
our $DEFAULT_TIMEOUT = 60; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub new { |
30
|
9
|
|
|
9
|
1
|
19664
|
my ($class, %param) = @_; |
31
|
|
|
|
|
|
|
|
32
|
9
|
|
|
|
|
88
|
$param{agent} = LWP::UserAgent->new(agent => sprintf('%s/%s', $class, $VERSION)); |
33
|
9
|
|
|
|
|
11156
|
$param{serializer} = JSON->new->utf8(1); |
34
|
9
|
|
100
|
|
|
63
|
$param{api_version} ||= $DEFAULT_API_VERSION; |
35
|
9
|
|
100
|
|
|
37
|
$param{timeout} ||= $DEFAULT_TIMEOUT; |
36
|
|
|
|
|
|
|
|
37
|
9
|
100
|
|
|
|
25
|
if (!defined $param{authorizer}) { |
38
|
|
|
|
|
|
|
my $authorizer = try { |
39
|
|
|
|
|
|
|
Net::Azure::Authorization::SAS->new(connection_string => $param{connection_string}) |
40
|
8
|
|
|
8
|
|
657
|
} catch { |
41
|
1
|
|
|
1
|
|
422
|
croak $_; |
42
|
8
|
|
|
|
|
61
|
}; |
43
|
7
|
|
|
|
|
1426
|
$param{authorizer} = $authorizer; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
8
|
|
|
|
|
79
|
bless {%param}, $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _uri { |
50
|
7
|
|
|
7
|
|
9645
|
my ($self, $path, %params) = @_; |
51
|
7
|
|
100
|
|
|
22
|
$path ||= '/'; |
52
|
7
|
|
|
|
|
25
|
my $uri = URI->new($self->authorizer->endpoint); |
53
|
7
|
|
|
|
|
14333
|
$uri->scheme('https'); |
54
|
7
|
|
|
|
|
9990
|
$uri->path($path); |
55
|
7
|
|
|
|
|
249
|
$uri->query_form(%params); |
56
|
7
|
|
|
|
|
433
|
$uri; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _req { |
60
|
7
|
|
|
7
|
|
14807
|
my ($self, $path, $payload, %params) = @_; |
61
|
7
|
100
|
|
|
|
52
|
croak 'path is reuired' if !defined $path; |
62
|
6
|
100
|
|
|
|
21
|
croak 'payload is required' if !defined $payload; |
63
|
5
|
100
|
|
|
|
21
|
croak 'payload is not hashref' if ref($payload) ne 'HASH'; |
64
|
4
|
|
100
|
|
|
32
|
$params{timeout} ||= $self->timeout; |
65
|
4
|
|
100
|
|
|
50
|
$params{api_version} ||= $self->api_version; |
66
|
4
|
|
|
|
|
31
|
my $uri = $self->_uri($path, %params); |
67
|
4
|
|
|
|
|
14
|
my $auth = $self->authorizer->token($uri->as_string); |
68
|
4
|
|
|
|
|
985
|
my $data = $self->serializer->encode($payload); |
69
|
4
|
|
|
|
|
83
|
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
|
|
|
|
|
857
|
$req->agent($self->agent); |
78
|
4
|
|
|
|
|
49
|
$req; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub message { |
82
|
1
|
|
|
1
|
1
|
1341
|
my ($self, $payload) = @_; |
83
|
1
|
|
|
|
|
5
|
my $path = sprintf "/%s/messages", $self->authorizer->{entity_path}; |
84
|
1
|
|
|
|
|
16
|
my $req = $self->_req($path => $payload); |
85
|
1
|
|
|
|
|
4
|
$req; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
__END__ |