line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MikroTik::Client::Response; |
2
|
4
|
|
|
4
|
|
56717
|
use MikroTik::Client::Mo; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
26
|
|
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
1441
|
use MikroTik::Client::Sentence; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
930
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has data => []; |
7
|
|
|
|
|
|
|
has sentence => sub { MikroTik::Client::Sentence->new() }; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub parse { |
10
|
36
|
|
|
36
|
1
|
108
|
my ($self, $buf) = @_; |
11
|
|
|
|
|
|
|
|
12
|
36
|
|
|
|
|
63
|
my $data = []; |
13
|
|
|
|
|
|
|
|
14
|
36
|
|
|
|
|
94
|
my $sentence = $self->sentence; |
15
|
36
|
|
|
|
|
92
|
while ($$buf) { |
16
|
53
|
|
|
|
|
146
|
my $words = $sentence->fetch($buf); |
17
|
53
|
100
|
|
|
|
111
|
last if $sentence->is_incomplete; |
18
|
|
|
|
|
|
|
|
19
|
50
|
|
|
|
|
165
|
my $item = {'.tag' => '', '.type' => (shift @$words)}; |
20
|
50
|
|
|
|
|
85
|
push @$data, $item; |
21
|
|
|
|
|
|
|
|
22
|
50
|
100
|
|
|
|
93
|
next unless @$words; |
23
|
|
|
|
|
|
|
|
24
|
49
|
|
|
|
|
100
|
while (my $w = shift @$words) { |
25
|
112
|
50
|
66
|
|
|
949
|
$item->{$1 || $2} = $3 if ($w =~ /^(?:=([^=]+)|(\.tag))=(.*)/); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
36
|
|
|
|
|
141
|
return $self->{data} = $data; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
1; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=encoding utf8 |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
MikroTik::Client::Response - Parse responses from a buffer |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
use MikroTik::Client::Response; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my $response = MikroTik::Client::Response->new(); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $list = $response->parse(\$buf); |
47
|
|
|
|
|
|
|
for my $re (@$list) { |
48
|
|
|
|
|
|
|
my ($type, $tag) = delete @{$re}{'.type'. '.tag'}; |
49
|
|
|
|
|
|
|
say "$_ => $re->{$_}" for keys %$re; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 DESCRIPTION |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Parser for API protocol responses. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
L implements the following attributes. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 data |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $items = $response->data; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Sentences fetched in last operation; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 sentence |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $sentence = $response->sentence; |
69
|
|
|
|
|
|
|
$response->sentence(MikroTik::Client::Sentence->new()); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
L object used to decode sentences from network buffer. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 METHODS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 parse |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $list = $response->parse(\$buf); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Parses data from a buffer and returns list of hashrefs with attributes for each |
80
|
|
|
|
|
|
|
sentence. There are some special attributes: |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=over 2 |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item '.tag' |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
'.tag' => 1 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Reply tag. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item '.type' |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
'.type' => '!re' |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Reply type. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=back |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SEE ALSO |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
L |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |