++ed by:

1 non-PAUSE user.

Andre Parker
and 1 contributors

NAME

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

SYNOPSIS

  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;

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 MikroTik::Client::Query.

Can be also called as an object method.

fetch

  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.

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 data from previous "fetch" call.

SEE ALSO

MikroTik::Client