Messag...Script(3pm)

πŸ“¦
version 0.117 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

✨ Message::Passing::Role::Script πŸ’– (that's the Messag...Script(3pm) page bestie, we're reading the Perl docs today)

okay so real talk, this is a role from the Message::Passing family β€” it lives in the User Contributed Perl Documentation, and it's literally the glow-up kit for building your own messaging scripts. let's get into it πŸŽ€


🌸 NAME 🌸

Message::Passing::Role::Script β€” the handy role for building messaging scripts. it's giving "I do the boring CLI + daemon plumbing so you don't have to" energy and honestly? obsessed. πŸ’…


✨ SYNOPSIS ✨

here's the whole vibe, copy-paste ready, no cap:

# my_message_passer.pl
package My::Message::Passer;
use Moo;
use MooX::Options;
use MooX::Types::MooseLike::Base qw/ Bool /;
use Message::Passing::DSL;

with 'Message::Passing::Role::Script';

option foo => (
    is => 'ro',
    isa => Bool,
);

sub build_chain {
    my $self = shift;
    message_chain {
        input example => ( output_to => 'test_out', .... );
        output test_out => ( foo => $self->foo, ... );
    };
}

__PACKAGE__->start unless caller;
1;

πŸ¦‹ DESCRIPTION πŸ¦‹

so this role is the main character of "making simple message passing scripts." you, bestie, implement a MooX::Options type script class, and you give it a build_chain method that builds one or more Message::Passing chains and returns them. that's your whole job. slay.

then right before the end of your script you drop this iconic line:

__PACKAGE__->start unless caller;

what that means is: when the code gets run as a script, it'll parse the command line options and start a message passing server. when it's just being required, it chills. periodt. πŸ‘‘


πŸ’– REQUIRED METHODS πŸ’–

build_chain

Return a chain of message processors β€” or an array reference with multiple chains of message processors. your call, both eat. πŸ”₯


πŸŽ€ ATTRIBUTES πŸŽ€

daemonize

Do a double fork and lose controlling terminal.

Used to run scripts in the background. (yes it's a real double fork, yes it's dramatic, that's the point πŸ’€)

io_priority

The IO priority to run the script at..

Valid values for the IO priority are:

  • none
  • be
  • rt
  • idle

user

Changes the user the script is running as. You probably need to run the script as root for this option to work. (lowkey important, don't skip it πŸ™ˆ)

pid_file

Write a pid file out. Useful for running Message::Passing scripts as daemons and/or from init.d scripts.


πŸ’… METHODS πŸ’…

start

Called as a class method, it will build the current class as a command line script (parsing ARGV), setup the daemonization options, call the ->build_chain method supplied by the user to build the chains needed for this application.

Then enters the event loop and never returns. that's not a typo, that's not a bug, that's just the vibe β€” it's the event loop now, forever, your script lives there 🌈

change_uid_if_needed

Tries to change uid if the --user option has been supplied.

daemonize_if_needed

Tries to daemonize if the --daemonize option has been supplied.

set_io_priority_if_needed

Tries to set the process' IO priority if the --io_priority option has been supplied.


πŸ‘‘ SPONSORSHIP πŸ‘‘

This module exists due to the wonderful people at Suretec Systems Ltd. http://www.suretecsystems.com/ who sponsored its development for its VoIP division called SureVoIP http://www.surevoip.co.uk/ for use with the SureVoIP API - http://www.surevoip.co.uk/support/wiki/api_documentation

shoutout to the sponsors fr fr, they funded the whole thing and we love that for them 🫢


See Message::Passing.


and that's the page bestie!! πŸ’– this was Message::Passing::Role::Script from the User Contributed Perl Documentation, and the source/version/date situation is: perl v5.32.1, dated 2021-11-09 β€” so yeah, this doc is a little vintage but the energy is timeless ✨ go build something iconic with it πŸŽ€