about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-08-01 08:12:24 +0000
committerEric Wong <e@yhbt.net>2020-08-02 08:26:17 +0000
commit9447bac572fccad88f8a1aacf0cd3aceef787182 (patch)
treeec9f2f6224ea9593430ffd1967ef22ebe9b1a7fa
parent3e5b497d0f7d415140da2caabf267d62711b83b4 (diff)
downloadpublic-inbox-9447bac572fccad88f8a1aacf0cd3aceef787182.tar.gz
We don't want `local $/' affecting Eml->new, and we can
use implicit returns which may be faster on older Perl.
-rw-r--r--lib/PublicInbox/InboxWritable.pm16
1 files changed, 6 insertions, 10 deletions
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;
         }
 }