| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 46 | 0 | my $reply = $callback->($line, $conn, $server); | |||||||||
| 47 | 0 | ▶ | last unless defined $reply; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | ▶ | $conn->($reply) if $reply; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||