API-MikroTik
view release on metacpan or search on metacpan
lib/API/MikroTik.pm view on Meta::CPAN
weaken $self;
$r->{timeout} = $r->{loop}
->timer($self->timeout => sub { $self->_fail($r, 'response timeout') });
return $r->{tag};
}
1;
=encoding utf8
=head1 NAME
API::MikroTik - Non-blocking interface to MikroTik API
=head1 SYNOPSIS
my $api = API::MikroTik->new();
# Blocking
lib/API/MikroTik/Query.pm view on Meta::CPAN
sub _value_scalar {
my ($name, $op, $val) = (shift, shift, shift // '');
return ("?$name=$val", '?#!') if $op eq '-not';
return '?' . $name . $op . $val;
}
1;
=encoding utf8
=head1 NAME
API::MikroTik::Query - Build MikroTik queries from perl structures
=head1 SYNOPSIS
use API::MikroTik::Query qw(build_query);
# (a = 1 OR a = 2) AND (b = 3 OR c = 4 OR d = 5)
lib/API/MikroTik/Response.pm view on Meta::CPAN
$item->{$1 || $2} = $3 if ($w =~ /^(?:=([^=]+)|(\.tag))=(.*)/);
}
}
return $self->{data} = $data;
}
1;
=encoding utf8
=head1 NAME
API::MikroTik::Response - Parse responses from a buffer
=head1 SYNOPSIS
use API::MikroTik::Response;
my $response = API::MikroTik::Response->new();
lib/API/MikroTik/Sentence.pm view on Meta::CPAN
}
elsif (($len & 0xf8) == 0xf0) {
$len = unpack 'N', substr $$buff, 0, 4, '';
}
return $len;
}
1;
=encoding utf8
=head1 NAME
API::MikroTik::Sentence - Encode and decode API sentences
=head1 SYNOPSIS
use API::MikroTik::Sentence qw(encode_sentence);
my $command = '/interface/print';
lib/API/MikroTik/Sentence.pm view on Meta::CPAN
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;
=head1 DESCRIPTION
Provides subroutines for encoding API sentences and parsing them back into words.
=head1 METHODS
=head2 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 L<API::MikroTik::Query/build_query>.
t/sentence.t view on Meta::CPAN
use warnings;
use strict;
use lib './';
use Test::More;
use API::MikroTik::Sentence qw(encode_sentence);
my $s = API::MikroTik::Sentence->new();
# length encoding
my ($packed, $len);
for (0x7f, 0x3fff, 0x1fffff, 0xfffffff, 0x10000000) {
$packed = API::MikroTik::Sentence::_encode_length($_);
($len, undef) = API::MikroTik::Sentence::_strip_length(\$packed);
is $len, $_, "length encoding: $_";
}
# encode word
my $encoded = API::MikroTik::Sentence::_encode_word('bla' x 3);
$encoded .= API::MikroTik::Sentence::_encode_word('bla' x 50);
is length($encoded), 162, 'right length';
is $s->_fetch_word(\$encoded), 'bla' x 3, 'right decoded word';
is length($encoded), 152, 'right length';
is $s->_fetch_word(\$encoded), 'bla' x 50, 'right decoded word';
( run in 0.367 second using v1.01-cache-2.11-cpan-4d50c553e7e )