Message::Passing::DSL - An easy way to make chains of Message::Passing components.
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;
This module provides a simple to use helper system for writing scripts which implement a Message::Passing server, like the built in message-pass script.
Rather than having to pass instances of an output to each input in the output_to attribute, and full class names, you can use short names for component classes, and strings for the output_to attribute, the DSL resolves these and deals with instance construction for you.
output_to
See example in the SYNOPSIS, and details for the exported sugar functions below.
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)).
Maintains a registry / factory for the log classes, which is used to allow the resolving of symbolic names in the output_to key to function.
Constructs a named output within a chain.
message_chain { output foo => ( class => 'STDOUT' ); .... };
Class names will be assumed to prefixed with 'Message::Passing::Output::', unless you prefix the class with + e.g. +My::Own::Output::Class
+My::Own::Output::Class
Constructs a named encoder within a chain.
message_chain { encoder fooenc => ( output_to => 'out', class => 'JSON' ); .... };
Class names will be assumed to prefixed with 'Message::Passing::Filter::Encoder::', unless you prefix the class with + e.g. +My::Own::Encoder::Class
+My::Own::Encoder::Class
Constructs a named filter (which can act as both an output and an input) within a chain.
message_chain { ... filter bar => ( output_to => 'fooenc', class => 'Null' ); ... };
Class names will be assumed to prefixed with 'Message::Passing::Filter::', unless you prefix the class with + e.g. +My::Own::Filter::Class
+My::Own::Filter::Class
Constructs a named decoder within a chain.
message_chain { decoder zmq_decode => ( output_to => 'filter', class => 'JSON' ); .... };
Class names will be assumed to prefixed with 'Message::Passing::Filter::Decoder::', unless you prefix the class with + e.g. +My::Own::Encoder::Class
The last thing in a chain - produces data which gets consumed.
message_chain { ... input zmq => ( output_to => 'zmq_decode', class => 'ZeroMQ', bind => '...' ); .... }
Setup the error logging output. Takes the same arguments as an input xxx => () block, except without a name.
input xxx => ()
This enters the event loop and causes log events to be consumed and processed.
Can be passed a message_chain to run, although this is entirely optional (as all chains which are still in scope will run when the event loop is entered).
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>
See Message::Passing.
To install Message::Passing, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Message::Passing
CPAN shell
perl -MCPAN -e shell install Message::Passing
For more information on module installation, please visit the detailed CPAN module installation guide.