From 9447bac572fccad88f8a1aacf0cd3aceef787182 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 1 Aug 2020 08:12:24 +0000 Subject: inboxwritable: mime_from_path: reduce `$/' scope and returns 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(-) (limited to 'lib/PublicInbox/InboxWritable.pm') diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm index 1f3f6672..e8ecd3fb 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; } } -- cgit v1.2.3-24-ge0c7