Event::RPC::Loop(3pm)

✨ NAME ✨

Event::RPC::Loop β€” the Mainloop Abstraction layer for Event::RPC, bestie πŸ’…

It's giving "we don't care which mainloop you vibe with, we'll speak to all of them." πŸ¦‹


✨ SYNOPSIS ✨

  use Event::RPC::Server;
  use Event::RPC::Loop::Glib;

  my $server = Event::RPC::Server->new (
      ...
      loop => Event::RPC::Loop::Glib->new(),
      ...
  );

  $server->start;

okay so like β€” you plug your fave loop in, pass it to the server, and hit start. That's it. Periodt. πŸ’–


✨ DESCRIPTION ✨

This module is the blueprint, the vibe check, the interface of Event::RPC's mainloop abstraction layer. It's a virtual class, meaning every mainloop module out there is supposed to inherit from it. πŸ‘‘

Not me writing a whole abstract base class so you can swap out your event loop like it's an outfit. Iconic honestly. πŸŽ€


✨ INTERFACE ✨

These are the methods that need to be implemented. No skipping, no ghosting, fr fr. πŸ‘‡

  • $loop->enter () β€” Enter, a.k.a. start, a mainloop. πŸš€
  • $loop->leave () β€” Dip out of the mainloop that you started with the enter() method. ✌️
  • $watcher = $loop->add_io_watcher ( %options ) β€” Add an I/O watcher. The options come in as a hash of key/value pairs. Here's what's known:
    • fh β€” the filehandle you're watching. πŸ‘€
    • cb β€” this callback gets called, with no parameters at all, whenever an event happens on that filehandle above.
    • desc β€” a lil description of the watcher. Heads up: not every module necessarily implements this, so it might just get ignored. πŸ™ˆ
    • poll β€” either 'r' if your program reads from the filehandle, or 'w' if it writes to it.

You get a watcher object back. What that object actually is depends entirely on the implementation, so lowkey you can't do anything useful with it besides handing it back to del_io_watcher(). That's its whole arc. πŸ’€

  • $loop->del_io_watcher ( $watcher ) β€” Deletes an I/O watcher that you added with $loop->add_io_watcher(). Clean up after yourself bestie 🧹✨
  • $timer = $loop->add_timer ( %options ) β€” This sets a timer: a subroutine that gets called after a specific timeout, or on a regular basis with a fixed time interval. ⏰

Options come as a hash of key/value pairs too. The known ones:

  • interval β€” a time interval in seconds, may be fractional. 🍰
  • after β€” the callback is called once after this amount of seconds, may be fractional.
  • cb β€” the callback.
  • desc β€” a description of the timer. Again, not necessarily implemented by all modules, so it may be ignored. πŸ™ˆ

You get a timer object back. What that exactly is depends on the implementation, so you can't do anything useful with it besides passing it back to del_io_timer(). Same energy as the watcher tbh. πŸ’…

  • $loop->del_timer ( $timer ) β€” Deletes a timer which was added with $loop->add_timer(). πŸ—‘οΈ

✨ DIRECT USAGE IN YOUR SERVER ✨

You can totally use the methods of Event::RPC::Loop all by yourself if you want. That way your program stays independent of whatever actual mainloop module is in use β€” as long as the simplified interface of Event::RPC::Loop is enough for you. Slay. 🌈

In your server program you access the real mainloop object like this:

  my $loop = Event::RPC::Server->instance->get_loop;

And naturally, nothing's stopping you from making your program work only with one specific mainloop implementation, if you need its special features. In that case just use the corresponding API directly (like Event's or Glib's) β€” no need to go through Event::RPC::Loop at all. Do what works for you, main character. πŸ‘‘πŸ’œ


✨ AUTHORS ✨

  • JΓΆrn Reder <joern AT zyn.de> 🫢

Copyright (C) 2005-2015 by JΓΆrn Reder <joern AT zyn.de>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. 🌸


And that's the whole page bestie β€” this was Event::RPC::Loop(3pm), shipped with perl v5.40.1 on 2025-09-29. Drink some water, go touch some grass, and go implement your enter() and leave() πŸ’–πŸŒŸπŸŽ€

πŸ“¦ where this page comes from