ZMQ - Perl-ish Interface libzmq
use ZMQ; use ZMQ::Constants qw(ZMQ_PUB); my $cxt = ZMQ::Context->new(5); my $sock = $cxt->socket( ZMQ_PUB ); $sock->bind( "tcp://192.168.11.5:9999" ); if ( $ZMQ::BACKEND eq 'ZMQ::LibZMQ2' ) { $sock->send( ZMQ::Message->new( "Hello" ) ); } elsif ( $ZMQ::BACKEND eq 'ZMQ::LibZMQ3' ) { $sock->sendmsg( ZMQ::Message->new( "Hello" ) ); }
ZMQ is a Perl-ish wrapper for libzmq. It uses ZMQ::LibZMQ2 or ZMQ::LibZMQ3 (ZMQ::LibZMQ2 is the default) as the actual backend.
If you want a one-to-one direct mapping to libzmq, then you should be using ZMQ::LibZMQ2 or ZMQ::LibZMQ3 directly
ZMQ will automatically choose the backend (either ZMQ::LibZMQ2 or ZMQ::LibZMQ3) to use. This can be explicitly specified by setting PERL_ZMQ_BACKEND environment variable.
PERL_ZMQ_BACKEND
By default ZMQ::LibZMQ2 will be used as the backend. This may change in future versions, so make sure to explicitly set your backend if you don't want it to change:
BEGIN { $ENV{ PERL_ZMQ_BACKEND } = 'ZMQ::LibZMQ2'; } use ZMQ;
If you think your code will be used from another program that also uses libzmq, you might want to consider using the ZMQ::LibZMQ* modules. This is because you can't write "truly" portable code using this high level interface (libzmq's API change rather drastically between versions). Personally, I'd recommend only using this module for your one-shot scripts, and use ZMQ::LibZMQ* for all other uses. YMMV.
Calls $funcname via whichever backend loaded by ZMQ.pm. For example if ZMQ::LibZMQ2 is loaded:
$funcname
use ZMQ; my $version = ZMQ::call( "zmq_version" ); # calls ZMQ::LibZMQ2::zmq_version
If @args is passed, they are passed directly to the target function.
@args
http://zeromq.org
http://github.com/lestrrat/p5-ZMQ
ZMQ::Context, ZMQ::Message, ZMQ::Socket, ZMQ::Poller
Daisuke Maki <daisuke@endeworks.jp>
<daisuke@endeworks.jp>
The ZMQ module is
Copyright (C) 2012 by Daisuke Maki
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.0 or, at your option, any later version of Perl 5 you may have available.
To install ZMQ, copy and paste the appropriate command in to your terminal.
cpanm
cpanm ZMQ
CPAN shell
perl -MCPAN -e shell install ZMQ
For more information on module installation, please visit the detailed CPAN module installation guide.