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-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 C2F9F1F5B1 for ; Sat, 1 Aug 2020 08:12:27 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/4] inboxwritable: mime_from_path: reduce `$/' scope and returns Date: Sat, 1 Aug 2020 08:12:24 +0000 Message-Id: <20200801081227.21412-2-e@yhbt.net> In-Reply-To: <20200801081227.21412-1-e@yhbt.net> References: <20200801081227.21412-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: We don't want `local $/' affecting Eml->new, and we can use implicit returns which may be faster on older Perl. --- lib/PublicInbox/InboxWritable.pm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm index 1f3f66728..e8ecd3fba 100644 --- a/lib/PublicInbox/InboxWritable.pm +++ b/lib/PublicInbox/InboxWritable.pm @@ -8,6 +8,7 @@ use warnings; use base qw(PublicInbox::Inbox); use PublicInbox::Import; use PublicInbox::Filter::Base qw(REJECT); +use Errno qw(ENOENT); use constant { PERM_UMASK => 0, @@ -135,16 +136,11 @@ sub is_maildir_path ($) { sub mime_from_path ($) { my ($path) = @_; if (open my $fh, '<', $path) { - local $/; - my $str = <$fh>; - $str or return; - return PublicInbox::Eml->new(\$str); - } elsif ($!{ENOENT}) { - # common with Maildir - return; - } else { - warn "failed to open $path: $!\n"; - return; + my $str = do { local $/; <$fh> } or return; + PublicInbox::Eml->new(\$str); + } else { # ENOENT is common with Maildir + warn "failed to open $path: $!\n" if $! != ENOENT; + undef; } }