Ion.pm

filter: Statementstmt 79.5% 35 / 44 Branchbran 16.6% 2 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 100% 3 / 3 totaltotal 70.4% 50 / 71 CC 7 SCAR 18.2
CC
7
Cov
66%
__ANON__
20.0
__ANON__
6.0
Service
3.5
CRAP 6.2
↑ Summary Ion/Conn.pm »
1 package Ion;
2 # ABSTRACT: A clear and concise API for writing TCP servers and clients
3 3 $Ion::VERSION = '0.06';
4 3 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Coro;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use AnyEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Ion::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Ion::Conn;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 our @EXPORT = qw(
15 Connect
16 Listen
17 Service
18 );
19  
20 sub Connect (;$$) {
21 3 ▶ my ($host, $port) = @_;
Subroutine Connect: called CC=2 SCAR=7.1
Pod documented
22 3 ▶ return Ion::Conn->new(handle => $host) if ref $host;
Branch: 1 branch
BranchTrueFalseTotal
if ref $host 0 3 3
23 3 return Ion::Conn->new(host => $host, port => $port);
24 }
25  
26 sub Listen (;$$) {
27 3 ▶ my ($port, $host) = @_;
Subroutine Listen: called CC=1 SCAR=0.0
Pod documented
28 3 Ion::Server->new(host => $host, port => $port);
29 }
30  
31 sub Service (&;$$) {
32 2 ▶ my $callback = shift;
Subroutine Service: called CC=2 SCAR=12.5
Pod documented
33 2 my $server = shift;
34 2 ▶ $server = Listen($server, shift) unless ref $server;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $server 2 0 2
35 2 $server->start;
36  
37 async_pool {
38 0 ▶ my ($callback, $server) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
39  
40 0 ▶ while (defined(my $conn = <$server>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $conn = readline $server)) 0 0 0
41 async_pool {
42 0 ▶ my ($callback, $conn, $server) = @_;
Subroutine __ANON__: not called CC=4 SCAR=30.0
43  
44 0 ▶ while (defined(my $line = <$conn>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $conn)) 0 0 0
45 0 my $reply = $callback->($line, $conn, $server);
46 0 ▶ last unless defined $reply;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $reply 0 0 0
47 0 ▶ $conn->($reply) if $reply;
Branch: 1 branch
BranchTrueFalseTotal
if $reply 0 0 0
48 }
49  
50 0 $conn->close;
51 0 } $callback, $conn, $server;
52 }
53  
54 2 } $callback, $server;
55  
56 2 return $server;
57 }
58  
59 3 1;
60  
61 __END__
↑ Summary Ion/Conn.pm »