about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiInspect.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-10-04 03:49:19 +0000
committerEric Wong <e@80x24.org>2023-10-04 17:46:35 +0000
commit2bac2c5e41de98f9aa50fbf69060a3bdef54f61f (patch)
tree2bae21bca9eec60c0439039c305e2716cc4d9697 /lib/PublicInbox/LeiInspect.pm
parent830ff2d76f38fed230eaa8fb8fc5a5e83917562a (diff)
downloadpublic-inbox-2bac2c5e41de98f9aa50fbf69060a3bdef54f61f.tar.gz
This will make switching $lei contexts less error-prone
and hopefully save us from some suprising bugs in the future.

Followup-to: 759885e60e59 (lei: ensure --stdin sets %ENV and $current_lei, 2023-09-14)
Diffstat (limited to 'lib/PublicInbox/LeiInspect.pm')
-rw-r--r--lib/PublicInbox/LeiInspect.pm28
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/PublicInbox/LeiInspect.pm b/lib/PublicInbox/LeiInspect.pm
index 0455e739..f801610f 100644
--- a/lib/PublicInbox/LeiInspect.pm
+++ b/lib/PublicInbox/LeiInspect.pm
@@ -251,24 +251,20 @@ sub inspect_start ($$) {
         $self->wq_close;
 }
 
+sub do_inspect { # lei->do_env cb
+        my ($lei) = @_;
+        my $str = delete $lei->{istr};
+        $str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
+        my $eml = PublicInbox::Eml->new(\$str);
+        inspect_start($lei, [ 'blob:'.$lei->git_oid($eml)->hexdigest,
+                        map { "mid:$_" } @{mids($eml)} ]);
+}
+
 sub ins_add { # InputPipe->consume callback
         my ($lei) = @_; # $_[1] = $rbuf
-        if (defined $_[1]) {
-                $_[1] eq '' and return eval {
-                        $lei->fchdir;
-                        local %ENV = %{$lei->{env}};
-                        local $PublicInbox::LEI::current_lei = $lei;
-                        my $str = delete $lei->{istr};
-                        $str =~ s/\A[\r\n]*From [^\r\n]*\r?\n//s;
-                        my $eml = PublicInbox::Eml->new(\$str);
-                        inspect_start($lei, [
-                                'blob:'.$lei->git_oid($eml)->hexdigest,
-                                map { "mid:$_" } @{mids($eml)} ]);
-                };
-                $lei->{istr} .= $_[1];
-        } else {
-                $lei->fail("error reading stdin: $!");
-        }
+        $_[1] // return $lei->fail("error reading stdin: $!");
+        return $lei->{istr} .= $_[1] if $_[1] ne '';
+        $lei->do_env(\&do_inspect);
 }
 
 sub lei_inspect {