MikroTik::Client::Sentence - Encode and decode API sentences
use MikroTik::Client::Sentence qw(encode_sentence); my $command = '/interface/print'; my $attr = {'.proplist' => '.id,name,type'}; my $query = {type => ['ipip-tunnel', 'gre-tunnel'], running => 'true'}; my $tag = 1; my $bytes = encode_sentence($command, $attr, $query, $tag); my $sentence = MikroTik::Client::Sentence->new(); my $words = $sentence->fetch(\$bytes); say $_ for @$words;
Provides subroutines for encoding API sentences and parsing them back into words.
my $bytes = encode_sentence($command, $attr, $query, $tag);
Encodes sentence. Attributes is a hashref with attribute-value pairs. Query will be parsed with "build_query" in MikroTik::Client::Query.
Can be also called as an object method.
my $words = $sentence->fetch(\$buf);
Fetches a sentence from a buffer and parses it into a list of API words. It will return empty list and set "is_incomplete" flag if amount of data in a buffer is unsufficient for parsing full sentence.
my $done = !$sentence->is_incomplete;
Indicates that a processed buffer was incomplete and remaining amount of data was insufficient to complete a sentence.
my $sentence->reset;
Clears an incomplete status and removes data from previous "fetch" call.
MikroTik::Client
To install MikroTik::Client, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MikroTik::Client
CPAN shell
perl -MCPAN -e shell install MikroTik::Client
For more information on module installation, please visit the detailed CPAN module installation guide.