blib/lib/ZMQ/LibZMQ3/LibZMQ2.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package ZMQ::LibZMQ3::LibZMQ2;
2  
3 9 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 0 ▶use ZMQ::LibZMQ3;
Subroutine BEGIN: called CC=1 SCAR=2.6
7  
8 =head1 NAME
9  
10 ZMQ::LibZMQ3::LibZMQ2 - Seamlessly Run LibZMQ Progs against LibZMQ3
11  
12 =cut
13  
14 our $VERSION = '0.03';
15  
16 =head1 SYNOPSIS
17  
18 This provides an interface compatible with ZMQ::LibZMQ2, but runs against
19 ZMQ::LibZMQ3. For more information and documentation, see ZMQ::LibZMQ2
20  
21 To port, assuming no fully qualified namespace calls, change
22  
23 #use ZMQ::LibZMQ2;
24  
25 to
26  
27 use ZMQ::LibZMQ3::LibZMQ2;
28  
29 =head2 Porting Implementation and Caveats
30  
31 There are a few specific issues that come up when porting LibZMQ2 applications
32 to LibZMQ3. This module attempts to provide a basic wrapper, preventing those
33 most common issues from surfacing. This is not intended for new development,
34 but for cases where existing code uses ZMQ::LibZMQ2 and you need to deploy
35 against LibZMQ3.
36  
37 The primary cases covered are:
38  
39 =over
40  
41 =item renamed methods
42  
43 For example, zmq_recv becomes zmq_recvmsg.
44  
45 =item different return value semantics
46  
47 For example, zmq_sendmsg returning positive ints on success on 3.x while
48 zmq_send returns 0 on success in libzmq2
49  
50 =item poll argument semantics
51  
52 The argument is now in miliseconds rather than microseconds, so without wrapping
53 this, applications poll for 1000 times as long.
54  
55 =back
56  
57 There are, however, a very few specific cases not covered by the porting layer.
58 For the most part these are internal details that programs hopefully avoid
59 caring about but they were found during the test cases copied from ZMQ::LibZMQ2.
60  
61 These include:
62  
63 =over
64  
65 =item object class names
66  
67 Objects are blessed in the LibZMQ3 namespace instead of the LibZMQ2 namespace.
68 For example, a socket is blessed as ZMQ::LibZMQ3::Socket rather than
69 ZMQ::LibZMQ2::Socket.
70  
71 =item object internals
72  
73 Object reference semantics are not guaranteed to be useful across
74 implementations. For example, sockets were blessed scalar references in
75 LibZMQ2, but they are not in LibZMQ3.
76  
77 =back
78  
79 The above caveats are fairly minor, and are expected not to affect most
80 applications.
81  
82 =head1 EXPORT
83  
84 =over
85  
86 =item zmq_errno
87  
88 =item zmq_strerror
89  
90 =item zmq_init
91  
92 =item zmq_socket
93  
94 =item zmq_bind
95  
96 =item zmq_connect
97  
98 =item zmq_close
99  
100 =item zmq_getsockopt
101  
102 =item zmq_setsockopt
103  
104 =item zmq_send
105  
106 =item zmq_recv
107  
108 =item zmq_msg_init
109  
110 =item zmq_msg_init_data
111  
112 =item zmq_msg_init_size
113  
114 =item zmq_msg_copy
115  
116 =item zmq_msg_move
117  
118 =item zmq_msg_close
119  
120 =item zmq_msg_poll
121  
122 =item zmq_version
123  
124 =item zmq_device
125  
126 =item zmq_getsockopt_int
127  
128 =item zmq_getsockopt_int64
129  
130 =item zmq_getsockopt_string
131  
132 =item zmq_getsockopt_uint64
133  
134 =item zmq_setsockopt_int
135  
136 =item zmq_setsockopt_int64
137  
138 =item zmq_setsockopt_string
139  
140 =item zmq_setsockopt_uint64
141  
142 =back
143  
144 =cut
145  
146 use base qw(Exporter);
147 ## no critic (ProhibitAutomaticExportation)
148 our @EXPORT = qw(
149 zmq_errno zmq_strerror
150 zmq_init zmq_term zmq_socket zmq_bind zmq_connect zmq_close
151 zmq_getsockopt zmq_setsockopt
152 zmq_send zmq_recv
153 zmq_msg_init zmq_msg_init_data zmq_msg_init_size
154 zmq_msg_data zmq_msg_size
155 zmq_msg_copy zmq_msg_move zmq_msg_close
156 zmq_poll zmq_version zmq_device
157 zmq_setsockopt_int zmq_setsockopt_int64 zmq_setsockopt_string
158 zmq_setsockopt_uint64 zmq_getsockopt_int zmq_getsockopt_int64
159 zmq_getsockopt_string zmq_getsockopt_uintint64
160 );
161  
162 # Function override map:
163 # libzmq2 => libzmq3
164 #
165 # if you need to skip, you can do
166 #
167 # libzmq2 => 0
168 #
169 # and then define your own function
170 my %fmap = (
171 zmq_send => 0,
172 zmq_recv => 'zmq_recvmsg',
173 zmq_poll => 0,
174 );
175  
176 {
177 no strict 'refs'; ## no critic (ProhibitNoStrict)
178 no warnings 'once'; ## no critic (ProhibitNoWarnings)
179 my $pkg = __PACKAGE__;
180 *{"${pkg}::$_->{export}"} = *{"ZMQ::LibZMQ3::$_->{import}"} for map {
181 my $target = $_;
182 $target = $fmap{$_} if exists $fmap{$_};
183 $target
184 ? {
185 import => $target,
186 export => $_
187 }
188 : ();
189 } @EXPORT;
190 };
191  
192 no warnings 'redefine'; ## no critic (ProhibitNoWarnings)
193  
194 sub zmq_poll {
195 my $timeout = pop @_;
196 push @_, $timeout / 1000;
197 return ZMQ::LibZMQ3::zmq_poll(@_);
198 }
199  
200 sub zmq_send {
201 my $rv = ZMQ::LibZMQ3::zmq_sendmsg(@_) || 0;
202 return $rv == -1 ? -1 : 0;
203 }
204  
205 =head1 AUTHOR
206  
207 Binary.com, C<< <perl at binary.com> >>
208  
209 =head1 BUGS
210  
211 Please report any bugs or feature requests to C<bug-zmq-libzmq2-libzmq3 at rt.cpan.org>, or through
212 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ZMQ-LibZMQ2-LibZMQ3>. I will be notified, and then you'll
213 automatically be notified of progress on your bug as I make changes.
214  
215  
216  
217  
218 =head1 SUPPORT
219  
220 You can find documentation for this module with the perldoc command.
221  
222 perldoc ZMQ::LibZMQ2::LibZMQ3
223  
224  
225 You can also look for information at:
226  
227 =over 4
228  
229 =item * RT: CPAN's request tracker (report bugs here)
230  
231 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ZMQ-LibZMQ2-LibZMQ3>
232  
233 =item * AnnoCPAN: Annotated CPAN documentation
234  
235 L<http://annocpan.org/dist/ZMQ-LibZMQ2-LibZMQ3>
236  
237 =item * CPAN Ratings
238  
239 L<http://cpanratings.perl.org/d/ZMQ-LibZMQ2-LibZMQ3>
240  
241 =item * Search CPAN
242  
243 L<http://search.cpan.org/dist/ZMQ-LibZMQ2-LibZMQ3/>
244  
245 =back
246  
247  
248 =head1 ACKNOWLEDGEMENTS
249  
250  
251 =head1 LICENSE AND COPYRIGHT
252  
253 Copyright 2014 Binary.com.
254  
255 This code is released under the Apache License version 2. Please see the
256 included LICENSE file.
257  
258 =head2 TEST SUITE COPYRIGHT AND LICENSE
259  
260 The Test Suite is copied from ZMQ::LibZMQ, is copyright Daisuke Maki
261 <daisuke@endeworks.jp> and Steffen Mueller, <smueller@cpan.org>.
262  
263 It is released uner the same terms as Perl itself.
264  
265  
266 =cut
267  
268 1; # End of ZMQ::LibZMQ2::LibZMQ3
↑ Summary