The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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);

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.

is_incomplete

  my $done = !$sentence->is_incomplete;

Indicates that processed sentence is incomplete and remaining amount of data are insufficient to complete request.

reset

  my $sentence->reset;

Clears incomplete status and removes remained buffer.

SEE ALSO

API::MikroTik