AnyEvent-FTP
view release on metacpan or search on metacpan
lib/AnyEvent/FTP/Server/Context.pm view on Meta::CPAN
package AnyEvent::FTP::Server::Context;
use strict;
use warnings;
use 5.010;
use Moo;
# ABSTRACT: FTP Server client context class
our $VERSION = '0.20'; # VERSION
with 'AnyEvent::FTP::Role::Event';
with 'AnyEvent::FTP::Server::Role::Context';
__PACKAGE__->define_events(qw( auth ));
has ready => (
is => 'rw',
default => sub { 1 },
);
has ascii_layer => (
is => 'rw',
default => ':raw:eol(CRLF-Native)'
);
sub push_request
{
my($self, $con, $req) = @_;
push @{ $self->{request_queue} }, [ $con, $req ];
$self->process_queue if $self->ready;
$self;
}
sub process_queue
{
my($self) = @_;
return $self unless @{ $self->{request_queue} } > 0;
$self->ready(0);
my($con, $req) = @{ shift @{ $self->{request_queue} } };
my $command = lc $req->command;
if($self->can('auth_command_check_hook'))
{
return unless $self->auth_command_check_hook($con, $command);
}
my $method = join '_', 'cmd', $command;
if($self->can($method))
{
$self->$method($con, $req);
}
else
{
$self->invalid_command($con, $req);
}
$self;
}
sub invalid_command
{
my($self, $con, $req) = @_;
$con->send_response(500 => $req->command . ' not understood');
$self->done;
}
sub invalid_syntax
{
my($self, $con, $raw) = @_;
$con->send_response(500 => 'Command not understood');
$self->done;
}
sub help_quit { "QUIT" }
( run in 0.969 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )