API::MikroTik::Sentence - Encode and decode API sentences.
use API::MikroTik::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 = API::MikroTik::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 API::MikroTik::Query.
Can be also called as an object method.
my $words = $sentence->fetch(\$buff);
Fetch sentence from a buffer and parse it into a list of API words. If called on an object marked as incomplete, will append data to previous results.
my $done = !$sentence->is_incomplete;
Indicates that processed sentence is incomplete and remaining amount of data are insufficient to complete request.
my $sentence->reset;
Clears incomplete status and removes remained buffer.
API::MikroTik
To install API::MikroTik, copy and paste the appropriate command in to your terminal.
cpanm
cpanm API::MikroTik
CPAN shell
perl -MCPAN -e shell install API::MikroTik
For more information on module installation, please visit the detailed CPAN module installation guide.