Messag...ng::DSL(3pm)
π Message::Passing::DSL β the manual, but make it cute π
okay bestie, so you know the page Messag...ng::DSL(3pm) from the User Contributed Perl Documentation? That's this one. Yes the name got truncated by the formatter, no we are not going to let that ruin our day. It's Message::Passing::DSL and it is genuinely a little gem. π
β¨ NAME β¨
Message::Passing::DSL β an easy way to make chains of Message::Passing components.
Like, an easy way. That's the whole point. That's the assignment and it ate. π«Ά
πΈ SYNOPSIS πΈ
package mylogcollectorscript;
use Moo;
use MooX::Options;
use Message::Passing::DSL;
use MooX::Types::MooseLike::Base qw/ Str /;
use namespace::clean -except => [qw( meta _options_data _options_config )];
with 'Message::Passing::Role::Script';
option socket_bind => (
is => 'ro',
isa => Str,
default => sub { 'tcp://*:5558' },
);
sub build_chain {
my $self = shift;
message_chain {
output console => (
class => 'STDOUT',
);
input zmq => (
class => 'ZeroMQ',
output_to => 'console',
socket_bind => $self->socket_bind,
);
};
}
__PACKAGE__->start unless caller;
1;
look at that. clean. no notes. π
π¦ DESCRIPTION π¦
So this module is a simple-to-use helper system for writing scripts that implement a Message::Passing server β same energy as the built-in message-pass script. It's giving "we made the boilerplate disappear" and honestly? iconic.
Here's the tea: normally you'd have to pass actual instances of an output to each input in the output_to attribute, and you'd have to write out full class names like a menace. With this DSL you can:
- use short names for component classes, and
- use strings for the
output_toattribute.
The DSL resolves all of that and deals with instance construction for you. no cap. π§
Check the example up in the SYNOPSIS, and the details for the exported sugar functions are right below. β¬οΈ
π FUNCTIONS π
message_chain
Constructs a message chain (i.e. a series of Message::Passing objects feeding into each other), warns about any unused parts of the chain, and returns an array ref to the heads of the chain (i.e. the input class(es)).
It also maintains a registry / factory for the log classes, which is what makes the resolving of symbolic names in the output_to key actually function. so that's the magic trick. β¨
output
Constructs a named output within a chain.
message_chain {
output foo => ( class => 'STDOUT' );
....
};
Class names will be assumed to be prefixed with 'Message::Passing::Output::', unless you prefix the class with +, e.g. "+My::Own::Output::Class".
encoder
Constructs a named encoder within a chain.
message_chain {
encoder fooenc => ( output_to => 'out', class => 'JSON' );
....
};
Class names will be assumed to be prefixed with 'Message::Passing::Filter::Encoder::', unless you prefix the class with +, e.g. "+My::Own::Encoder::Class".
filter
Constructs a named filter within a chain β and a filter is the multitasker of the group because it can act as both an output and an input. main character energy, fr.
message_chain {
...
filter bar => ( output_to => 'fooenc', class => 'Null' );
...
};
Class names will be assumed to be prefixed with 'Message::Passing::Filter::', unless you prefix the class with +, e.g. "+My::Own::Filter::Class".
decoder
Constructs a named decoder within a chain.
message_chain {
decoder zmq_decode => ( output_to => 'filter', class => 'JSON' );
....
};
Class names will be assumed to be prefixed with 'Message::Passing::Filter::Decoder::', unless you prefix the class with +, e.g. "+My::Own::Encoder::Class".
input
The last thing in a chain β it produces data which gets consumed.
message_chain {
...
input zmq => ( output_to => 'zmq_decode', class => 'ZeroMQ', bind => '...' );
....
}
Class names will be assumed to be prefixed with 'Message::Passing::Output::', unless you prefix the class with +, e.g. "+My::Own::Output::Class".
error_log
Sets up the error logging output. Takes the same arguments as an "input xxx => ()" block, except without a name. (No name, no problem. π)
run_message_server
This enters the event loop and causes log events to be consumed and processed.
You can pass it a message_chain to run, although this is entirely optional β because all chains which are still in scope will run when the event loop is entered. lowkey convenient. π
π 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, they really said "we fund open source" and that's beautiful. π«Άβ¨
π AUTHOR, COPYRIGHT AND LICENSE π
See Message::Passing. (short and sweet, we love a cross-reference.)
okay that's the whole page, you're welcome, go build a chain and slay π this was Messag...ng::DSL(3pm) from perl v5.32.1, dated 2021-11-09, and yes I'm mentioning the version and date because the footer said so and I never skip details. mwah. π
π
π¦ 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