line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MikroTik::Client::Response; |
2
|
5
|
|
|
5
|
|
69381
|
use MikroTik::Client::Mo; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
34
|
|
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
2349
|
use MikroTik::Client::Sentence; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
1415
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has data => []; |
7
|
|
|
|
|
|
|
has sentence => sub { MikroTik::Client::Sentence->new() }; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub parse { |
10
|
37
|
|
|
37
|
1
|
125
|
my ($self, $buf) = @_; |
11
|
|
|
|
|
|
|
|
12
|
37
|
|
|
|
|
75
|
my $data = []; |
13
|
|
|
|
|
|
|
|
14
|
37
|
|
|
|
|
103
|
my $sentence = $self->sentence; |
15
|
37
|
|
|
|
|
102
|
while ($$buf) { |
16
|
54
|
|
|
|
|
153
|
my $words = $sentence->fetch($buf); |
17
|
54
|
100
|
|
|
|
121
|
last if $sentence->is_incomplete; |
18
|
|
|
|
|
|
|
|
19
|
51
|
|
|
|
|
183
|
my $item = {'.tag' => '', '.type' => (shift @$words)}; |
20
|
51
|
|
|
|
|
103
|
push @$data, $item; |
21
|
|
|
|
|
|
|
|
22
|
51
|
100
|
|
|
|
104
|
next unless @$words; |
23
|
|
|
|
|
|
|
|
24
|
50
|
|
|
|
|
124
|
while (my $w = shift @$words) { |
25
|
113
|
50
|
66
|
|
|
954
|
$item->{$1 || $2} = $3 if ($w =~ /^(?:=([^=]+)|(\.tag))=(.*)/s); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
37
|
|
|
|
|
162
|
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 |