ZMQ::Declare::DSL - DSL for declaring 0MQ infrastructure
use ZMQ::Declare::DSL; my $zdcf = declare_zdcf { app { name 'weather'; context { iothreads 1 }; device { name 'client'; sock { name 'weather_stream'; type 'sub'; conn qw(tcp://localhost:12345); option subscribe => "70123"; # ZIP code in this example }; }; device { name 'server'; sock { name 'weather_publisher'; type 'pub'; bnd qw(tcp://*:12345); }; }; }; }; # elsewhere my $server = $zdcf->application("weather")->device('server'); $server->implementation(sub { my ($runtime) = @_; # server main loop here return(); }); $server->run(); # yet elsewhere my $client = $zdcf->application("weather")->device('client'); $client->implementation(sub { my ($runtime) = @_; # client main loop here return(); }); $client->run();
This is experimental software. Interfaces and implementation are subject to change. If you are interested in using this in production, please get in touch to gauge the current state of stability.
This module defines a domain specific language (which just so happens to be valid Perl that's slightly beaten into shape) for declaring 0MQ infrastructure. Please read ZMQ::Declare before you proceed with this document.
This module is just a thin syntax-sugar layer on top of simply creating a regular nested Perl data structure and passing it to ZMQ::Declare::ZDCF-new()>. It adds no features beyond a different syntax. Unless you find the syntax very attractive, consider using a simpler way to declare 0MQ infrastructure.
ZMQ::Declare::ZDCF-
Generally speaking, there are multiple kinds of functions in this module: There are those that have a notion of scope, such as the outer declare_zdcf BLOCK and app BLOCK, context BLOCK, device BLOCK, and socket BLOCK. And there are those that simply set a property of the enclosing object (well, scope): name STRING, type STRING, bnd LIST, conn LIST, option LIST, and iothreads INTEGER.
declare_zdcf BLOCK
app BLOCK
context BLOCK
device BLOCK
socket BLOCK
name STRING
type STRING
bnd LIST
conn LIST
option LIST
iothreads INTEGER
Most of these can only occurr within certain scopes. For example, iothreads can only be set within a context and a context can only appear within an app, but a name is valid in an app, a device, or a socket. Etc.
iothreads
context
app
name
device
socket
This module exports a plethora of functions (as of this writing, all functions that are documented below) by default. That's the point.
The outermost function that starts the declaration of a new ZDCF specification containing zero or more apps.
Defines a new app within a ZDCF specification. Only valid within the outermost declare_zdcf block. Must cointain at least a name property.
declare_zdcf
Can contain one or more devices.
Defines a threading context of an app. Can occur zero or one time per app, but cannot be used outside an app or inside its substructures (like devices).
Defines the number of iothreads in a threading context. Defaults to one. This is the only property that is currently valid in a context.
Defines a single device within an app. Can occur zero or more times in each app. Not valid outside of an app definition or within its substructures.
Can contain zero or more sockets. May have a type and a name property. The name defaults to the app name, but that requires that the app name declaration appears before the device declaration.
Defines a single socket within a device. Can occur zero or more times in each device. Not valid outside of a device definition or within its substructures.
Requires at least a name and a type property and at least one bind or connect property.
Defines the name of the enclosing object. Valid for apps, devices, and sockets.
Defines the type of the enclosing object. Valid for devices and sockets.
Given a list of endpoints (strings), adds to the set of endpoints that the enclosing socket is to bind to.
Valid any number of times within a socket. Either bnd or conn need to appear at least once in a socket.
bnd
conn
Same as bnd, but for connecting to sockets instead of binding.
Given a list of key/value pairs, sets socket options. Valid any number of times within a socket.
ZMQ::Declare
ZeroMQ
Steffen Mueller <smueller@cpan.org>
Copyright (C) 2012 by Steffen Mueller
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.
To install ZMQ::Declare, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ZMQ::Declare
CPAN shell
perl -MCPAN -e shell install ZMQ::Declare
For more information on module installation, please visit the detailed CPAN module installation guide.