File Coverage

blib/lib/AnyEvent/FTP/Server/Connection.pm
Criterion Covered Total %
statement 27 28 96.4
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 39 41 95.1


line stmt bran cond sub pod time code
1             package AnyEvent::FTP::Server::Connection;
2              
3 25     25   162213 use strict;
  25         54  
  25         653  
4 25     25   106 use warnings;
  25         51  
  25         626  
5 25     25   438 use 5.010;
  25         110  
6 25     25   500 use Moo;
  25         8369  
  25         462  
7 25     25   15793 use AnyEvent::FTP::Request;
  25         54  
  25         6724  
8              
9             # ABSTRACT: FTP Server connection class
10             our $VERSION = '0.19'; # VERSION
11              
12             with 'AnyEvent::FTP::Role::Event';
13              
14             __PACKAGE__->define_events(qw( request response close ));
15              
16             has context => (
17             is => 'ro',
18             required => 1,
19             );
20              
21             has response_encoder => (
22             is => 'ro',
23             lazy => 1,
24             default => sub {
25             require AnyEvent::FTP::Server::UnambiguousResponseEncoder;
26             AnyEvent::FTP::Server::UnambiguousResponseEncoder->new;
27             },
28             );
29              
30             has ip => (
31             is => 'ro',
32             required => 1,
33             );
34              
35             sub process_request
36             {
37 677     677 1 8150 my($self, $line) = @_;
38              
39 677         1157 my $raw = $line;
40              
41 677         1916 $self->emit(request => $raw);
42              
43 677         1175 $line =~ s/\015?\012//g;
44              
45 677 50       2545 if($line =~ s/^([A-Z]{1,4})\s?//i)
46             {
47 677         4060 $self->context->push_request($self, AnyEvent::FTP::Request->new(uc $1, $line, $raw));
48             }
49             else
50             {
51 0         0 $self->context->invalid_syntax($self, $raw);
52             }
53              
54 677         2285 $self;
55             }
56              
57             sub send_response
58             {
59 813     813 1 2490 my $self = shift;
60 813         14000 my $raw = $self->response_encoder->encode(@_);
61 813         2508 $self->emit(response => $raw);
62 813         2216 $self;
63             }
64              
65             sub close
66             {
67 80     80 1 178 my($self) = shift;
68 80         196 $self->emit('close');
69             }
70              
71             1;
72              
73             __END__