Messag...Script(3pm)
β¨ 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:
nonebertidle
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 π«Ά
π AUTHOR, COPYRIGHT AND LICENSE π
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 π
π¦ where this page comes from
- debian bookworm: libmessage-passing-perl 0.117-1 Β· LGPL-2.1-only
- debian trixie: libmessage-passing-perl 0.117-1 Β· LGPL-2.1-only
- ubuntu jammy: libmessage-passing-perl 0.117-1 Β· LGPL-2.1-only
- ubuntu noble: libmessage-passing-perl 0.117-1 Β· LGPL-2.1-only
- ubuntu resolute: libmessage-passing-perl 0.117-1 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms