1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
package AnyEvent::FTP::Server::UnambiguousResponseEncoder;
use strict;
use warnings;
use 5.010;
use Moo;
# ABSTRACT: Server response encoder that encodes responses so they cannot be confused
our $VERSION = '0.20'; # VERSION
with 'AnyEvent::FTP::Server::Role::ResponseEncoder';
sub encode
{
my $self = shift;
my $code;
my $message;
if(ref $_[0])
{
$code = $_[0]->code;
$message = $_[0]->message;
}
else
{
($code, $message) = @_;
}
$message = [ $message ] unless ref($message) eq 'ARRAY';
my $last = pop @$message;
return join "\015\012", (map { "$code-$_" } @$message), "$code $last\015\012";
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
AnyEvent::FTP::Server::UnambiguousResponseEncoder - Server response encoder that encodes responses so they cannot be confused
=head1 VERSION
version 0.20
=head1 SYNOPSIS
use AnyEvent::FTP::Server::UnambiguousResponseEncoder;
my $encoder = AnyEvent::FTP::Server::UnambiguousResponseEncoder->new;
# encode a FTP welcome message
my $message = $encoder->encode(220, 'welcome to myftpd');
=head1 DESCRIPTION
Objects of this class are used to encode responses which are returned to
the client from the server.
=head1 METHODS
=head2 encode
my $str = $encoder->encode( $res );
my $str = $encoder->encode( $code, $message );
Returns the encoded message. You can pass in either a
L<AnyEvent::FTP::Response> object, or a code message pair.
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Ryo Okamoto
Shlomi Fish
José Joaquín Atria
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2017-2022 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|