From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 365A51F463 for ; Sun, 22 Dec 2019 00:12:45 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] nntp: simplify method detection using UNIVERSAL::can Date: Sun, 22 Dec 2019 00:12:45 +0000 Message-Id: <20191222001245.25332-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: No need to do an eval dance or disable strict refs. --- lib/PublicInbox/NNTP.pm | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 3d3ad539..65c0519a 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -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);