Non-blocking MikroTik API client.
Find a file
2025-10-28 13:21:00 +02:00
lib/MikroTik Bump version 2025-10-28 13:21:00 +02:00
t Fix Connection and AnyEvent tests (again) 2025-10-28 00:16:18 +02:00
.gitignore Cleanup .gitignore 2025-10-20 12:56:38 +03:00
.travis.yml Remove 5.32 from build list 2021-05-06 17:34:23 +03:00
Changes Fix Connection and AnyEvent tests (again) 2025-10-28 00:16:18 +02:00
LICENSE License 2018-02-09 11:12:14 +00:00
Makefile.PL Fix an email 2025-10-23 19:53:30 +03:00
MANIFEST.SKIP Initial commit 2017-11-19 13:20:43 +00:00
README.md Switch back to Mojo::IOLoop for event loop backend 2025-10-23 14:34:12 +03:00

MikroTik::Client - Non-blocking interface to MikroTik API.

Blocking and non-blocking API interface with queries and command subscriptions.

  my $api = MikroTik::Client->new();

  # Blocking
  my $list = $api->command(
      '/interface/print',
      {'.proplist' => '.id,name,type'},
      {type        => ['ipip-tunnel', 'gre-tunnel'], running => 'true'}
  );
  if (my $err = $api->error) { die "$err\n" }
  printf "%s: %s\n", $_->{name}, $_->{type} for @$list;


  # Non-blocking
  my $tag = $api->command(
      '/system/resource/print',
      {'.proplist' => 'board-name,version,uptime'} => sub {
          my ($api, $err, $list) = @_;
          ...;
      }
  );
  Mojo::IOLoop->start();

  # Subscribe
  $tag = $api->subscribe(
      '/interface/listen' => sub {
          my ($api, $err, $res) = @_;
          ...;
      }
  );
  Mojo::IOLoop->timer(3 => sub { $api->cancel($tag) });
  Mojo::IOLoop->start();

  # Errors handling
  $api->command(
      '/random/command' => sub {
          my ($api, $err, $list) = @_;

          if ($err) {
              warn "Error: $err, category: " . $list->[0]{category};
              return;
          }

          ...;
      }
  );
  Mojo::IOLoop->start();

  # Promises
  $api->cmd_p('/interface/print')
      ->then(sub { my $res = shift }, sub { my ($err, $attr) = @_ })
      ->finally(sub { Mojo::IOLoop->stop() });
  Mojo::IOLoop->start();