File Coverage

blib/lib/AnyEvent/FTP/Server/Role/Help.pm
Criterion Covered Total %
statement 35 36 97.2
branch 7 8 87.5
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 49 53 92.4


line stmt bran cond sub pod time code
1             package AnyEvent::FTP::Server::Role::Help;
2              
3 25     25   19000 use strict;
  25         62  
  25         1024  
4 25     25   123 use warnings;
  25         48  
  25         1324  
5 25     25   455 use 5.010;
  25         112  
6 25     25   144 use Moo::Role;
  25         92  
  25         221  
7              
8             # ABSTRACT: Help role for FTP server
9             our $VERSION = '0.20'; # VERSION
10              
11              
12             my %cmds;
13              
14 6     6 0 24 sub help_help { 'HELP [ command]' }
15              
16             sub cmd_help
17             {
18 108     108 0 219 my($self, $con, $req) = @_;
19              
20 108         288 my $topic = $req->args;
21 108         362 $topic =~ s/^\s+//;
22 108         276 $topic =~ s/\s+$//;
23 108         239 $topic = lc $topic;
24              
25 108 100       627 if($topic eq '')
    100          
26             {
27 6         37 my $class = ref $self;
28 6 100       43 unless(defined $cmds{$class})
29             {
30 25     25   17939 no strict 'refs';
  25         82  
  25         8254  
31             $cmds{$class} = [
32 4         10 sort map { my $x = $_; $x =~ s/^cmd_//; uc $x } grep /^cmd_/, keys %{$class . '::'}
  70         117  
  70         158  
  70         155  
  4         225  
33             ];
34             }
35              
36             $con->send_response(214, [
37             'The following commands are recognized:',
38 6         40 join(' ', @{ $cmds{$class} }),
  6         73  
39             'Direct comments to devnull@bogus',
40             ]);
41             }
42             elsif($self->can("cmd_$topic"))
43             {
44 99         209 my $method = "help_$topic";
45 99 50       535 if($self->can("help_$topic"))
46             {
47 99         459 $con->send_response(214 => 'Syntax: ' . $self->$method)
48             }
49             else
50             {
51 0         0 $con->send_response(502 => uc($topic) . " is a command without help");
52             }
53             }
54             else
55             {
56 3         10 $con->send_response(502 => 'Unknown command');
57             }
58              
59 108         555 $self->done;
60             }
61              
62             1;
63              
64             __END__