Ion.pm

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