ZeroMQ.pm

filter: Statementstmt 80.0% 8 / 10 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 85.7% 12 / 14 CC 1 SCAR 0.7
CC
1
Cov
80%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« ZeroMQ/Handle.pm ↑ Summary ZeroMQ/Pull.pm »
1 package AnyEvent::ZeroMQ;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $AnyEvent::ZeroMQ::VERSION = '0.01';
4 }
5 # ABSTRACT: non-blocking interface to ZeroMQ sockets
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 0 ▶use ZeroMQ::Raw;
Subroutine BEGIN: called CC=1 SCAR=2.6
10 use ZeroMQ::Raw::Constants qw(ZMQ_FD ZMQ_POLLIN ZMQ_POLLOUT ZMQ_EVENTS);
11 use Carp qw(confess);
12  
13 use namespace::autoclean;
14 use AnyEvent;
15  
16 sub io {
17 my ($class, %args) = @_;
18 my $poll = $args{poll} || confess 'must supply poll direction';
19 my $sock = $args{socket} || confess 'must supply socket';
20 my $cb = $args{cb} || confess 'must supply cb';
21  
22 my $fd = $sock->getsockopt(ZMQ_FD);
23 confess 'getsockopt did not return a valid fd!'
24 unless defined $fd;
25  
26 my $mask = $poll eq 'w' ? ZMQ_POLLOUT :
27 $poll eq 'r' ? ZMQ_POLLIN :
28 confess "invalid poll direction '$poll'";
29  
30 return AnyEvent->io(
31 poll => $poll,
32 fh => $fd,
33 cb => sub {
34 $cb->() if (($sock->getsockopt(ZMQ_EVENTS) & $mask) == $mask);
35 },
36 );
37 }
38  
39 sub probe {
40 my ($class, %args) = @_;
41 my $poll = $args{poll} || confess 'must supply poll direction';
42 my $sock = $args{socket} || confess 'must supply socket';
43  
44 my $mask = $poll eq 'w' ? ZMQ_POLLOUT :
45 $poll eq 'r' ? ZMQ_POLLIN :
46 confess "invalid poll direction '$poll'";
47  
48 return (($sock->getsockopt(ZMQ_EVENTS) & $mask) == $mask)
49 }
50  
51 1;
52  
53 __END__
« ZeroMQ/Handle.pm ↑ Summary ZeroMQ/Pull.pm »