| 1 | package AnyEvent::SKKServ; | ||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 1 | ▶ | use 5.008005; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | 1 | ▶ | use AnyEvent::Handle; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | 1 | ▶ | use AnyEvent::Socket (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 1 | ▶ | use constant { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 1 | CLIENT_END => '0', | |||||||||||||||||||||
| 12 | CLIENT_REQUEST => '1', | ||||||||||||||||||||||
| 13 | CLIENT_VERSION => '2', | ||||||||||||||||||||||
| 14 | CLIENT_HOST => '3', | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | SERVER_ERROR => '0', | ||||||||||||||||||||||
| 17 | SERVER_FOUND => '1', | ||||||||||||||||||||||
| 18 | SERVER_NOT_FOUND => '4', | ||||||||||||||||||||||
| 19 | SERVER_FULL => '9', | ||||||||||||||||||||||
| 20 | 1 | }; | |||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | 0 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 23 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||
| 24 | return bless { | ||||||||||||||||||||||
| 25 | host => undef, | ||||||||||||||||||||||
| 26 | port => 55100, | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | 0 | ▶ | on_error => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 29 | 0 | $_[0]->push_write(SERVER_ERROR . "\n"); | |||||||||||||||||||||
| 30 | }, | ||||||||||||||||||||||
| 31 | 0 | ▶ | on_end => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 32 | 0 | undef $_[0]; | |||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||
| 34 | 0 | ▶ | on_version => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 35 | 0 | $_[0]->push_write("$VERSION:anyevent_skkserv "); | |||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||
| 37 | 0 | ▶ | on_host => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 38 | # unimplemented | ||||||||||||||||||||||
| 39 | 0 | $_[0]->push_write("hostname:addr:...: "); | |||||||||||||||||||||
| 40 | }, | ||||||||||||||||||||||
| 41 | 0 | ▶ | on_request => sub {}, | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 42 | 0 | %args, | |||||||||||||||||||||
| 43 | }, $class; | ||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | 0 | ▶ | sub run { | ||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 47 | 0 | my $self = shift; | |||||||||||||||||||||
| 48 | 0 | ▶ | AnyEvent::Socket::tcp_server $self->{host}, $self->{port}, sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 49 | 0 | ▶ | my ($fh, $host, $port) = @_ or die "connection failed: $!"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 50 | 0 | my $hdl; $hdl = AnyEvent::Handle->new( | |||||||||||||||||||||
| 51 | fh => $fh, | ||||||||||||||||||||||
| 52 | 0 | ▶ | on_eof => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 53 | 0 | $_[0]->destroy; | |||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||
| 55 | 0 | ▶ | on_error => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 56 | 0 | $_[0]->destroy; | |||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||||
| 58 | 0 | ); | |||||||||||||||||||||
| 59 | 0 | ▶ | $hdl->on_read(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 60 | 0 | ▶ | $hdl->push_read(chunk => 1, sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||
| 61 | 0 | my ($hdl, $command) = @_; | |||||||||||||||||||||
| 62 | 0 | ▶ | if ($command eq CLIENT_END) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 63 | 0 | $self->{on_end}->(@_); | |||||||||||||||||||||
| 64 | } elsif ($command eq CLIENT_REQUEST) { | ||||||||||||||||||||||
| 65 | 0 | ▶ | $hdl->push_read(regex => qr/\x20/, sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 66 | 0 | chop $_[1]; | |||||||||||||||||||||
| 67 | 0 | $self->{on_request}->(@_); | |||||||||||||||||||||
| 68 | 0 | }); | |||||||||||||||||||||
| 69 | } elsif ($command eq CLIENT_VERSION) { | ||||||||||||||||||||||
| 70 | 0 | $self->{on_version}->(@_); | |||||||||||||||||||||
| 71 | } elsif ($command eq CLIENT_HOST) { | ||||||||||||||||||||||
| 72 | 0 | $self->{on_host}->(@_); | |||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||
| 74 | 0 | $self->{on_error}->(@_); | |||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||
| 76 | 0 | }); | |||||||||||||||||||||
| 77 | 0 | }); | |||||||||||||||||||||
| 78 | 0 | }; | |||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | 1 | 1; | |||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||||