++ed by:

1 non-PAUSE user.

Andre Parker
and 1 contributors

NAME

API::MikroTik::Sentence - Encode and decode API sentences

SYNOPSIS

  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;

DESCRIPTION

Provides subroutines for encoding API sentences and parsing them back into words.

METHODS

encode_sentence

  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.

fetch

  my $words = $sentence->fetch(\$buff);

Fetches a sentence from a buffer and parses it into a list of API words. In a situation when amount of data in the buffer are insufficient to complete the sentence, already processed words and the remaining buffer will be stored in an object. On a next call will prepend a buffer with kept data and merge a result with the one stored from a previous call.

is_incomplete

  my $done = !$sentence->is_incomplete;

Indicates that a processed buffer was incomplete and remaining amount of data was insufficient to complete a sentence.

reset

  my $sentence->reset;

Clears an incomplete status and removes a remaining buffer.

SEE ALSO

API::MikroTik