Passing/Input/Socket/UDP.pm

filter: Statementstmt 60.6% 20 / 33 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 41.6% 5 / 12 Podpod 0.0% 0 / 1 totaltotal 54.3% 25 / 46 SCAR 0.6
CC
1
Cov
61%
__ANON__
2.0
_default_port
2.0
BUILD
2.0
CRAP 1.1
« Passing/Role/Filter.pm ↑ Summary Passing/Filter/Decoder/Bzip2.pm »
1 package Message::Passing::Input::Socket::UDP;
2 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use AnyEvent::Handle::UDP;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Scalar::Util qw/ weaken /;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 with qw/
9 Message::Passing::Role::Input
10 Message::Passing::Role::HasHostnameAndPort
11 Message::Passing::Role::HasErrorChain
12 /;
13  
14 has '+hostname' => (
15 0 ▶ default => sub { 'localhost' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 2 );
17  
18 2 has '+port' => (
19 required => 1,
20 );
21  
22 0 ▶sub _default_port { die "You must supply a port #" }
Subroutine _default_port: not called CC=1 SCAR=6.9
23  
24 2 has handle => (
25 is => 'ro',
26 builder => '_build_handle',
27 lazy => 1,
28 );
29  
30 sub BUILD {
31 0 ▶ my $self = shift;
Subroutine BUILD: not called CC=1 SCAR=6.9
Pod undocumented
32 0 $self->handle;
33 }
34  
35 sub _send_data {
36 0 ▶ my ($self, $data, $from_addr) = @_;
Subroutine _send_data: not called CC=1 SCAR=6.9
37 0 $self->output_to->consume($data);
38 }
39  
40 sub _build_handle {
41 0 ▶ my $self = shift;
Subroutine _build_handle: not called CC=1 SCAR=6.9
42 0 weaken($self);
43 AnyEvent::Handle::UDP->new(
44 bind => [ $self->hostname, $self->port ],
45 on_recv => sub {
46 0 ▶ my ($data, $h, $from_addr) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 # The output can optionally drop from addr.
48 0 $self->_send_data($data, $from_addr);
49 },
50 on_error => sub {
51 0 ▶ my ($h, $fatal, $msg) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 $self->error->consume($msg);
53 },
54 0 );
55 }
56  
57 2 1;
58  
59 =head1 NAME
60  
61 Message::Passing::Input::Socket::UDP - UDP input
62  
63 =head1 DESCRIPTION
64  
65 An input which gets messages from a UDP network socket using
66 L<AnyEvent::Handle::UDP>.
67  
68 =head1 ATTRIBUTES
69  
70 =head2 hostname
71  
72 The hostname L<AnyEvent::Handle::UDP/new> will bind to.
73  
74 =head2 port
75  
76 The port L<AnyEvent::Handle::UDP/new> will bind to.
77  
78 =head1 SEE ALSO
79  
80 L<Message::Passing>
81  
82 =head1 SPONSORSHIP
83  
84 This module exists due to the wonderful people at Suretec Systems Ltd.
85 <http://www.suretecsystems.com/> who sponsored its development for its
86 VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with
87 the SureVoIP API -
88 <http://www.surevoip.co.uk/support/wiki/api_documentation>
89  
90 =head1 AUTHOR, COPYRIGHT AND LICENSE
91  
92 See L<Message::Passing>.
93  
94 =cut
95  
« Passing/Role/Filter.pm ↑ Summary Passing/Filter/Decoder/Bzip2.pm »