| 1 | package AnyEvent::FTP::Server::Context; | ||||||||||
| 2 | |||||||||||
| 3 | 25 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 25 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 25 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 25 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # ABSTRACT: FTP Server client context class | ||||||||||
| 9 | 25 | our $VERSION = '0.19'; # VERSION | |||||||||
| 10 | |||||||||||
| 11 | 25 | with 'AnyEvent::FTP::Role::Event'; | |||||||||
| 12 | 25 | with 'AnyEvent::FTP::Server::Role::Context'; | |||||||||
| 13 | |||||||||||
| 14 | 25 | __PACKAGE__->define_events(qw( auth )); | |||||||||
| 15 | |||||||||||
| 16 | has ready => ( | ||||||||||
| 17 | is => 'rw', | ||||||||||
| 18 | 69 | ▶ | default => sub { 1 }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 25 | ); | |||||||||
| 20 | |||||||||||
| 21 | 25 | has ascii_layer => ( | |||||||||
| 22 | is => 'rw', | ||||||||||
| 23 | default => ':raw:eol(CRLF-Native)' | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | sub push_request | ||||||||||
| 27 | { | ||||||||||
| 28 | 674 | ▶ | my($self, $con, $req) = @_; | ||||||||
|
Subroutine
push_request: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 29 | |||||||||||
| 30 | 674 | push @{ $self->{request_queue} }, [ $con, $req ]; | |||||||||
| 31 | |||||||||||
| 32 | 674 | ▶ | $self->process_queue if $self->ready; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | |||||||||||
| 34 | 674 | $self; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub process_queue | ||||||||||
| 38 | { | ||||||||||
| 39 | 1264 | ▶ | my($self) = @_; | ||||||||
|
Subroutine
process_queue: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 40 | |||||||||||
| 41 | 1264 | ▶ | return $self unless @{ $self->{request_queue} } > 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | |||||||||||
| 43 | 674 | $self->ready(0); | |||||||||
| 44 | |||||||||||
| 45 | 674 | my($con, $req) = @{ shift @{ $self->{request_queue} } }; | |||||||||
| 46 | |||||||||||
| 47 | 674 | my $command = lc $req->command; | |||||||||
| 48 | |||||||||||
| 49 | 674 | ▶ | if($self->can('auth_command_check_hook')) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | { | ||||||||||
| 51 | 674 | ▶ | return unless $self->auth_command_check_hook($con, $command); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 650 | my $method = join '_', 'cmd', $command; | |||||||||
| 55 | |||||||||||
| 56 | 650 | ▶ | if($self->can($method)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | { | ||||||||||
| 58 | 649 | $self->$method($con, $req); | |||||||||
| 59 | } | ||||||||||
| 60 | else | ||||||||||
| 61 | { | ||||||||||
| 62 | 1 | $self->invalid_command($con, $req); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 650 | $self; | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | sub invalid_command | ||||||||||
| 69 | { | ||||||||||
| 70 | 1 | ▶ | my($self, $con, $req) = @_; | ||||||||
|
Subroutine
invalid_command: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 71 | 1 | $con->send_response(500 => $req->command . ' not understood'); | |||||||||
| 72 | 1 | $self->done; | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | sub invalid_syntax | ||||||||||
| 76 | { | ||||||||||
| 77 | 0 | ▶ | my($self, $con, $raw) = @_; | ||||||||
|
Subroutine
invalid_syntax: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 78 | 0 | $con->send_response(500 => 'Command not understood'); | |||||||||
| 79 | 0 | $self->done; | |||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 1 | ▶ | sub help_quit { "QUIT" } | ||||||||
|
Subroutine
help_quit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 83 | |||||||||||
| 84 | sub cmd_quit | ||||||||||
| 85 | { | ||||||||||
| 86 | 41 | ▶ | my($self, $con, $req) = @_; | ||||||||
|
Subroutine
cmd_quit: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 87 | 41 | $con->send_response(221 => 'Goodbye'); | |||||||||
| 88 | 41 | $con->close; | |||||||||
| 89 | 41 | $self; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | sub done | ||||||||||
| 93 | { | ||||||||||
| 94 | 631 | ▶ | my($self) = @_; | ||||||||
|
Subroutine
done: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 95 | 631 | $self->ready(1); | |||||||||
| 96 | 631 | $self->process_queue; | |||||||||
| 97 | 631 | $self; | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 25 | 1; | |||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||