line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::ZeroMQ::Publish; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
3
|
|
|
3
|
|
48645
|
$AnyEvent::ZeroMQ::Publish::VERSION = '0.01'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: Non-blocking OO abstraction over ZMQ_PUB publish/subscribe sockets |
6
|
3
|
|
|
3
|
|
3608
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use MooseX::Aliases; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use true; |
10
|
|
|
|
|
|
|
use namespace::autoclean; |
11
|
|
|
|
|
|
|
use ZeroMQ::Raw::Constants qw(ZMQ_PUB); |
12
|
|
|
|
|
|
|
use Params::Util qw(_CODELIKE); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'AnyEvent::ZeroMQ::Role::WithHandle' => |
15
|
|
|
|
|
|
|
{ socket_type => ZMQ_PUB, socket_direction => 'w' }, |
16
|
|
|
|
|
|
|
'MooseX::Traits'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has '+_trait_namespace' => ( default => 'AnyEvent::ZeroMQ::Publish::Trait' ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub mangle_message { |
21
|
|
|
|
|
|
|
my ($self, $msg, %args) = @_; |
22
|
|
|
|
|
|
|
warn 'ignoring unused mangle arguments '. join(', ', map { "'$_'" } keys %args) |
23
|
|
|
|
|
|
|
if %args; |
24
|
|
|
|
|
|
|
return $msg; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub publish { |
28
|
|
|
|
|
|
|
my ($self, $msg, %args) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
if(_CODELIKE($msg)){ # not to be confused with 'if _CATLIKE($tobias)' |
31
|
|
|
|
|
|
|
$self->handle->push_write(sub { |
32
|
|
|
|
|
|
|
my $txt = $msg->(@_); |
33
|
|
|
|
|
|
|
return $self->mangle_message($txt, %args); |
34
|
|
|
|
|
|
|
}); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
|
|
|
|
|
|
$self->handle->push_write($self->mangle_message($msg, %args)); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
alias 'push_write' => 'publish'; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
with 'AnyEvent::ZeroMQ::Handle::Role::Generic', |
44
|
|
|
|
|
|
|
'AnyEvent::ZeroMQ::Handle::Role::Writable'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
AnyEvent::ZeroMQ::Publish - Non-blocking OO abstraction over ZMQ_PUB publish/subscribe sockets |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
version 0.01 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 AUTHOR |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Jonathan Rockway <jrockway@cpan.org> |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Jonathan Rockway. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
68
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|