AnyEvent/FTP/Server.pm

filter: Statementstmt 65.1% 73 / 112 Branchbran 50.0% 2 / 4 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 67.7% 21 / 31 Podpod 50.0% 1 / 2 totaltotal 63.8% 99 / 155 SCAR 15.6
CC
4
Cov
64%
start
2.1
_start_standalone
2.0
BUILD
2.0
CRAP 4.7
« AnyEvent/FTP/Server/Role/Help.pm ↑ Summary AnyEvent/FTP/Client/Response.pm »
1 package AnyEvent::FTP::Server;
2  
3 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use AnyEvent::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 24 ▶use AnyEvent::Socket qw( tcp_server );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 24 ▶use AnyEvent::FTP::Server::Connection;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 24 ▶use Socket qw( unpack_sockaddr_in inet_ntoa );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: Simple asynchronous ftp server
13 24 our $VERSION = '0.19'; # VERSION
14  
15  
16 24 ▶$AnyEvent::FTP::Server::VERSION //= 'dev';
Condition50%1/2
$AnyEvent::FTP::Server::VERSION //= "dev"
l!l
240
MC/DC0%0/1
$AnyEvent::FTP::Server::VERSION //= "dev"
$AnyEvent::FTP::Server::VERSION
Truth table50%1/2
A
A= $AnyEvent::FTP::Server::VERSION
Aresult
11
00
17  
18 24 with 'AnyEvent::FTP::Role::Event';
19  
20 24 __PACKAGE__->define_events(qw( bind connect ));
21  
22  
23 24 has hostname => (
24 is => 'ro',
25 );
26  
27  
28 has port => (
29 is => 'ro',
30 0 ▶ default => sub { 21 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 24 );
32  
33  
34 has default_context => (
35 is => 'ro',
36 0 ▶ default => sub { 'AnyEvent::FTP::Server::Context::FSRW' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 24 );
38  
39  
40 has welcome => (
41 is => 'ro',
42 28 ▶ default => sub { [ 220 => "aeftpd $AnyEvent::FTP::Server::VERSION" ] },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 24 );
44  
45  
46 24 has bindport => (
47 is => 'rw',
48 );
49  
50  
51 has inet => (
52 is => 'ro',
53 28 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
54 24 );
55  
56 sub BUILD
57 {
58 28 ▶ eval 'use ' . shift->default_context;
Subroutine BUILD: called CC=2 SCAR=7.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Pod undocumented
59 28 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 28 28
60 }
61  
62  
63 sub start
64 {
65 28 ▶ my($self) = @_;
Subroutine start: called CC=2 SCAR=7.2
Pod documented
66 28 ▶ $self->inet ? $self->_start_inet : $self->_start_standalone;
Branch: 1 branch
BranchTrueFalseTotal
$self->inet ? : 0 28 28
67 }
68  
69 sub _start_inet
70 {
71 0 ▶ my($self) = @_;
Subroutine _start_inet: not called CC=1 SCAR=6.9
72  
73 my $con = AnyEvent::FTP::Server::Connection->new(
74 context => $self->{default_context}->new,
75 0 ip => do {
76 0 my $sockname = getsockname STDIN;
77 0 my ($sockport, $sockaddr) = unpack_sockaddr_in ($sockname);
78 0 inet_ntoa ($sockaddr);
79 },
80 );
81  
82 0 my $handle;
83 $handle = AnyEvent::Handle->new(
84 fh => *STDIN,
85 on_error => sub {
86 0 ▶ my($hdl, $fatal, $msg) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 $con->close;
88 0 $_[0]->destroy;
89 0 undef $handle;
90 0 undef $con;
91 },
92 on_eof => sub {
93 0 ▶ $con->close;
Subroutine __ANON__: not called CC=1 SCAR=6.9
94 0 $handle->destroy;
95 0 undef $handle;
96 0 undef $con;
97 },
98 0 );
99  
100 0 $self->emit(connect => $con);
101  
102 0 STDOUT->autoflush(1);
103 0 STDIN->autoflush(1);
104  
105 $con->on_response(sub {
106 0 ▶ my($raw) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
107 0 print STDOUT $raw;
108 0 });
109  
110 $con->on_close(sub {
111 0 ▶ close STDOUT;
Subroutine __ANON__: not called CC=1 SCAR=6.9
112 0 exit;
113 0 });
114  
115 0 $con->send_response(@{ $self->welcome });
116  
117 $handle->on_read(sub {
118 $handle->push_read( line => sub {
119 0 ▶ my($handle, $line) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
120 0 $con->process_request($line);
121 0 ▶ });
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 0 });
123  
124 0 $self;
125 }
126  
127 sub _start_standalone
128 {
129 28 ▶ my($self) = @_;
Subroutine _start_standalone: called CC=2 SCAR=7.0
130  
131 my $prepare = sub {
132 28 ▶ my($fh, $host, $port) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
133 28 $self->bindport($port);
134 28 $self->emit(bind => $port);
135 28 };
136  
137 my $connect = sub {
138 69 ▶ my($fh, $host, $port) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.1
139  
140 my $con = AnyEvent::FTP::Server::Connection->new(
141 context => $self->{default_context}->new,
142 69 ip => do {
143 69 my($port, $addr) = unpack_sockaddr_in getsockname $fh;
144 69 inet_ntoa $addr;
145 },
146 );
147  
148 69 my $handle;
149 $handle = AnyEvent::Handle->new(
150 fh => $fh,
151 on_error => sub {
152 0 ▶ my($hdl, $fatal, $msg) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
153 0 $con->close;
154 0 $_[0]->destroy;
155 0 undef $handle;
156 0 undef $con;
157 },
158 on_eof => sub {
159 39 ▶ $con->close;
Subroutine __ANON__: called CC=1 SCAR=0.0
160 39 $handle->destroy;
161 39 undef $handle;
162 39 undef $con;
163 },
164 69 );
165  
166 69 $self->emit(connect => $con);
167  
168 $con->on_response(sub {
169 813 ▶ my($raw) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
170 813 $handle->push_write($raw);
171 69 });
172  
173 $con->on_close(sub {
174 80 ▶ $handle->push_shutdown;
Subroutine __ANON__: called CC=1 SCAR=0.0
175 69 });
176  
177 69 $con->send_response(@{ $self->welcome });
178  
179 $handle->on_read(sub {
180 $handle->push_read( line => sub {
181 674 ▶ my($handle, $line) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
182 674 $con->process_request($line);
183 674 ▶ });
Subroutine __ANON__: called CC=1 SCAR=0.0
184 69 });
185  
186 28 };
187  
188 28 ▶ tcp_server $self->hostname, $self->port || undef, $connect, $prepare;
Condition50%1/2
$self->port || undef
l!l
028
MC/DC0%0/1
$self->port || undef
$self->port
Truth table50%1/2
A
A= $self->port
Aresult
11
00
189  
190 28 $self;
191 }
192  
193 24 1;
194  
195 __END__
« AnyEvent/FTP/Server/Role/Help.pm ↑ Summary AnyEvent/FTP/Client/Response.pm »