IProto/Server.pm

filter: Statementstmt 56.3% 31 / 55 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 6 / 14 Podpod 0.0% 0 / 1 totaltotal 51.3% 37 / 72 CC 2 SCAR 7.6
CC
2
Cov
54%
__ANON__
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.1
« IProto/Role/Debuggable.pm ↑ Summary SilverBox.pm »
1 package MR::IProto::Server;
2  
3 =head1 NAME
4  
5 =head1 DESCRIPTION
6  
7 =cut
8  
9 1 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use AnyEvent::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use MR::IProto::Server::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 with 'MR::IProto::Role::Debuggable';
16  
17 has prefix => (
18 is => 'ro',
19 isa => 'Str',
20 0 ▶ default => sub { ref shift },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 1 );
22  
23 1 has host => (
24 is => 'ro',
25 isa => 'Str',
26 default => '0.0.0.0',
27 );
28  
29 1 has port => (
30 is => 'ro',
31 isa => 'Int',
32 required => 1,
33 );
34  
35 1 has handler => (
36 is => 'ro',
37 isa => 'CodeRef',
38 required => 1,
39 );
40  
41 1 has on_accept => (
42 is => 'ro',
43 isa => 'CodeRef',
44 );
45  
46 1 has on_close => (
47 is => 'ro',
48 isa => 'CodeRef',
49 );
50  
51 1 has on_error => (
52 is => 'ro',
53 isa => 'CodeRef',
54 );
55  
56 1 has _guard => (
57 is => 'ro',
58 lazy_build => 1,
59 );
60  
61 has _connections => (
62 is => 'ro',
63 isa => 'HashRef',
64 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 1 );
66  
67 1 has _recv_payload => (
68 is => 'ro',
69 isa => 'CodeRef',
70 lazy_build => 1,
71 );
72  
73 0 ▶sub run {
Subroutine run: not called CC=1 SCAR=6.9
Pod undocumented
74 0 my ($self) = @_;
75 0 $self->_guard;
76 0 return;
77 }
78  
79 0 ▶sub _build_debug_cb {
Subroutine _build_debug_cb: not called CC=1 SCAR=6.9
80 0 my ($self) = @_;
81 0 my $prefix = $self->prefix;
82 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
83 0 my ($msg) = @_;
84 0 chomp $msg;
85 0 warn sprintf "%s: %s\n", $prefix, $msg;
86 0 return;
87 0 };
88 }
89  
90 0 ▶sub _build__guard {
Subroutine _build__guard: not called CC=1 SCAR=6.9
91 0 my ($self) = @_;
92 0 weaken($self);
93 0 ▶ return tcp_server $self->host, $self->port, sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 0 my ($fh, $host, $port) = @_;
95 my $connection = MR::IProto::Server::Connection->new(
96 fh => $fh,
97 host => $host,
98 port => $port,
99 handler => $self->handler,
100 on_accept => $self->on_accept,
101 0 ▶ on_close => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
102 0 my ($connection) = @_;
103 0 my $key = sprintf "%s:%d", $connection->host, $connection->port;
104 0 delete $self->_connections->{$key};
105 0 ▶ $self->on_close->($connection) if $self->on_close;
Branch: 1 branch
BranchTrueFalseTotal
if $self->on_close 0 0 0
106 0 return;
107 },
108 0 on_error => $self->on_error,
109 debug => $self->debug,
110 debug_cb => $self->debug_cb,
111 );
112 0 $self->_connections->{"$host:$port"} = $connection;
113 0 return;
114 0 };
115 }
116  
117 1 ▶no Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 1 __PACKAGE__->meta->make_immutable();
119  
120 1 1;
« IProto/Role/Debuggable.pm ↑ Summary SilverBox.pm »