about summary refs log tree commit homepage
path: root/lib/PublicInbox/LEI.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-17 22:23:48 +0000
committerEric Wong <e@80x24.org>2020-12-19 09:32:08 +0000
commit7ab46690f51a7f1f22299e4fd385a56e5bcddef7 (patch)
treeeb6ef659c4633e971d69828518b57d997c8c1fd8 /lib/PublicInbox/LEI.pm
parentb28dcf96700a79616e7338bb8610f89155dd57e4 (diff)
downloadpublic-inbox-7ab46690f51a7f1f22299e4fd385a56e5bcddef7.tar.gz
Drop emit(), since we hard code the channel (client FD) 99% of
the time and use prototypes to avoid parentheses because my
hands are tired.
Diffstat (limited to 'lib/PublicInbox/LEI.pm')
-rw-r--r--lib/PublicInbox/LEI.pm23
1 files changed, 8 insertions, 15 deletions
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index c28c9b59..97c5d91b 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -250,18 +250,13 @@ sub x_it ($$) { # pronounced "exit"
 
 sub puts ($;@) { print { shift->{1} } map { "$_\n" } @_ }
 
-sub emit {
-        my ($self, $channel) = @_; # $buf = $_[2]
-        print { $self->{$channel} } $_[2] or die "print FD[$channel]: $!";
-}
+sub out ($;@) { print { shift->{1} } @_ }
 
-sub err {
-        my ($self, $buf) = @_;
-        $buf .= "\n" unless $buf =~ /\n\z/s;
-        emit($self, 2, $buf);
+sub err ($;@) {
+        print { shift->{2} } @_, (substr($_[-1], -1, 1) eq "\n" ? () : "\n");
 }
 
-sub qerr { $_[0]->{opt}->{quiet} or err(@_) }
+sub qerr ($;@) { $_[0]->{opt}->{quiet} or err(shift, @_) }
 
 sub fail ($$;$) {
         my ($self, $buf, $exit_code) = @_;
@@ -341,8 +336,7 @@ EOF
                 $msg .= $rhs;
                 $msg .= "\n";
         }
-        my $channel = $errmsg ? 2 : 1;
-        emit($self, $channel, $msg);
+        print { $self->{$errmsg ? 2 : 1} } $msg;
         x_it($self, $errmsg ? 1 << 8 : 0); # stderr => failure
         undef;
 }
@@ -404,7 +398,6 @@ sub optparse ($$$) {
                 }
                 last if $err;
         }
-        # warn "inf=$inf ".scalar(@$argv). ' '.scalar(@args)."\n";
         if (!$inf && scalar(@$argv) > scalar(@args)) {
                 $err //= 'too many arguments';
         }
@@ -413,7 +406,7 @@ sub optparse ($$$) {
 
 sub dispatch {
         my ($self, $cmd, @argv) = @_;
-        local $SIG{__WARN__} = sub { err($self, "@_") };
+        local $SIG{__WARN__} = sub { err($self, @_) };
         return _help($self, 'no command given') unless defined($cmd);
         my $func = "lei_$cmd";
         $func =~ tr/-/_/;
@@ -525,7 +518,7 @@ E: leistore.dir=$cur already initialized and it is not $dir
         return qerr($self, $exists);
 }
 
-sub lei_daemon_pid { emit($_[0], 1, "$$\n") }
+sub lei_daemon_pid { puts shift, $$ }
 
 sub lei_daemon_kill {
         my ($self) = @_;
@@ -547,7 +540,7 @@ sub lei_daemon_env {
                 my $eor = $opt->{z} ? "\0" : "\n";
                 my $buf = '';
                 while (my ($k, $v) = each %ENV) { $buf .= "$k=$v$eor" }
-                emit($self, 1, $buf)
+                out $self, $buf;
         }
 }