]> Sergey Matveev's repositories - public-inbox.git/commitdiff
inboxwritable: mime_from_path: reduce `$/' scope and returns
authorEric Wong <e@yhbt.net>
Sat, 1 Aug 2020 08:12:24 +0000 (08:12 +0000)
committerEric Wong <e@yhbt.net>
Sun, 2 Aug 2020 08:26:17 +0000 (08:26 +0000)
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

index 1f3f66728fcc25ce3b1ee1d3c145cf586aec057e..e8ecd3fba37023f51669a8abeb32e57491b41e8c 100644 (file)
@@ -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;
        }
 }