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   225673 use strict;
  25         69  
  25         858  
4 25     25   139 use warnings;
  25         63  
  25         725  
5 25     25   551 use 5.010;
  25         96  
6 25     25   662 use Moo;
  25         11507  
  25         397  
7 25     25   20384 use AnyEvent::FTP::Request;
  25         64  
  25         9343  
8              
9             # ABSTRACT: FTP Server connection class
10             our $VERSION = '0.18'; # 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 11039 my($self, $line) = @_;
38              
39 677         1249 my $raw = $line;
40              
41 677         2758 $self->emit(request => $raw);
42              
43 677         1663 $line =~ s/\015?\012//g;
44              
45 677 50       3313 if($line =~ s/^([A-Z]{1,4})\s?//i)
46             {
47 677         5455 $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         3600 $self;
55             }
56              
57             sub send_response
58             {
59 813     813 1 3456 my $self = shift;
60 813         20048 my $raw = $self->response_encoder->encode(@_);
61 813         3348 $self->emit(response => $raw);
62 813         3457 $self;
63             }
64              
65             sub close
66             {
67 80     80 1 241 my($self) = shift;
68 80         308 $self->emit('close');
69             }
70              
71             1;
72              
73             __END__