]> Sergey Matveev's repositories - public-inbox.git/commitdiff
nntp: simplify method detection using UNIVERSAL::can
authorEric Wong <e@80x24.org>
Sun, 22 Dec 2019 00:12:45 +0000 (00:12 +0000)
committerEric Wong <e@80x24.org>
Sun, 22 Dec 2019 03:55:12 +0000 (03:55 +0000)
No need to do an eval dance or disable strict refs.

lib/PublicInbox/NNTP.pm

index 6cd2b84ce7725abd7857c5be71fe4520db6c1525..5c23e476d42061288a668fd0a1fe03450582504f 100644 (file)
@@ -81,10 +81,7 @@ sub process_line ($$) {
        my ($self, $l) = @_;
        my ($req, @args) = split(/[ \t]/, $l);
        return 1 unless defined($req); # skip blank line
-       $req = eval {
-               no strict 'refs';
-               *{'cmd_'.lc($req)}{CODE};
-       };
+       $req = $self->can('cmd_'.lc($req));
        return res($self, '500 command not recognized') unless $req;
        return res($self, r501) unless args_ok($req, scalar @args);
 
@@ -173,11 +170,7 @@ sub cmd_list ($;$$) {
                my $arg = shift @args;
                $arg =~ tr/A-Z./a-z_/;
                $arg = "list_$arg";
-
-               $arg = eval {
-                       no strict 'refs';
-                       *{$arg}{CODE};
-               };
+               $arg = $self->can($arg);
                return r501 unless $arg && args_ok($arg, scalar @args);
                more($self, '215 information follows');
                $arg->($self, @args);