]> Sergey Matveev's repositories - public-inbox.git/commitdiff
treewide: kill problematic "$h->{k} //= do {" assignments
authorEric Wong <e@80x24.org>
Mon, 1 Nov 2021 19:06:09 +0000 (19:06 +0000)
committerEric Wong <e@80x24.org>
Mon, 1 Nov 2021 19:49:39 +0000 (19:49 +0000)
As stated in the previous change, conditional hash assignments
which trigger other hash assignments seem problematic, at times.
So replace:

$h->{k} //= do { $h->{x} = ...; $val };

$h->{k} // do {
$h->{x} = ...;
$hk->{k} = $val
};

"||=" is affected the same way, and some instances of "||=" are
replaced with "//=" or "// do {", now.

lib/PublicInbox/Config.pm
lib/PublicInbox/Git.pm
lib/PublicInbox/IMAP.pm
lib/PublicInbox/Inbox.pm
lib/PublicInbox/LEI.pm
lib/PublicInbox/SharedKV.pm
lib/PublicInbox/WWW.pm
lib/PublicInbox/WwwStatic.pm
lib/PublicInbox/WwwStream.pm

index 41117ac535d49678020bdddb4f5e79092794defa..0f002e5e62c260fbb5078bbbb25c67b1468fbbec 100644 (file)
@@ -377,8 +377,8 @@ sub get_1 {
 
 sub repo_objs {
        my ($self, $ibxish) = @_;
-       my $ibx_code_repos = $ibxish->{coderepo} or return;
-       $ibxish->{-repo_objs} //= do {
+       my $ibx_code_repos = $ibxish->{coderepo} // return;
+       $ibxish->{-repo_objs} // do {
                my $code_repos = $self->{-code_repos};
                my @repo_objs;
                for my $nick (@$ibx_code_repos) {
@@ -395,10 +395,9 @@ sub repo_objs {
                        push @repo_objs, $repo if $repo;
                }
                if (scalar @repo_objs) {
-                       \@repo_objs;
+                       $ibxish ->{-repo_objs} = \@repo_objs;
                } else {
                        delete $ibxish->{coderepo};
-                       undef;
                }
        }
 }
index 4078dd5b7cfe79f8bf1c0d29cfbe4b3cba35aae5..309f80dbfcf001e51f130cddee1a14ee38303dd3 100644 (file)
@@ -71,7 +71,7 @@ sub new {
 
 sub git_path ($$) {
        my ($self, $path) = @_;
-       $self->{-git_path}->{$path} ||= do {
+       $self->{-git_path}->{$path} //= do {
                local $/ = "\n";
                chomp(my $str = $self->qx(qw(rev-parse --git-path), $path));
 
index 4a7ff2f457d0458c317d452764e6d20abb7d1734..58a0a9e37c441601c907a485f6ece5c8aee4d24f 100644 (file)
@@ -871,12 +871,12 @@ sub eml_index_offs_i { # PublicInbox::Eml::each_part callback
 # prepares an index for BODY[$SECTION_IDX] fetches
 sub eml_body_idx ($$) {
        my ($eml, $section_idx) = @_;
-       my $idx = $eml->{imap_all_parts} //= do {
+       my $idx = $eml->{imap_all_parts} // do {
                my $all = {};
                $eml->each_part(\&eml_index_offs_i, $all, 0, 1);
                # top-level of multipart, BODY[0] not allowed (nz-number)
                delete $all->{0};
-               $all;
+               $eml->{imap_all_parts} = $all;
        };
        $idx->{$section_idx};
 }
index b7b71268187e86ce8f6f583e5391d645da8fb7f5..1579d500136a8f814f532275f486bc117c3e0441 100644 (file)
@@ -48,7 +48,7 @@ sub _cleanup_later ($) {
 sub _set_limiter ($$$) {
        my ($self, $pi_cfg, $pfx) = @_;
        my $lkey = "-${pfx}_limiter";
-       $self->{$lkey} ||= do {
+       $self->{$lkey} //= do {
                # full key is: publicinbox.$NAME.httpbackendmax
                my $mkey = $pfx.'max';
                my $val = $self->{$mkey} or return;
index 78b49a3bc1afca5d837884cf0cf6ac1a24b5fa77..3e1706a0dd20258508666db347f85e75aee8d344 100644 (file)
@@ -130,9 +130,10 @@ sub url_folder_cache {
 
 sub ale {
        my ($self) = @_;
-       $self->{ale} //= do {
+       $self->{ale} // do {
                require PublicInbox::LeiALE;
-               $self->_lei_cfg(1)->{ale} //= PublicInbox::LeiALE->new($self);
+               my $cfg = $self->_lei_cfg(1);
+               $self->{ale} = $cfg->{ale} //= PublicInbox::LeiALE->new($self);
        };
 }
 
@@ -1159,10 +1160,10 @@ sub event_step {
 sub event_step_init {
        my ($self) = @_;
        my $sock = $self->{sock} or return;
-       $self->{-event_init_done} //= do { # persist til $ops done
+       $self->{-event_init_done} // do { # persist til $ops done
                $sock->blocking(0);
                $self->SUPER::new($sock, EPOLLIN);
-               $sock;
+               $self->{-event_init_done} = $sock;
        };
 }
 
index 27407f8357131ef24f6388a934afae734a312528..4297efedb05742a7cd222c993546768c75cbde8e 100644 (file)
@@ -15,7 +15,7 @@ use File::Path qw(rmtree make_path);
 
 sub dbh {
        my ($self, $lock) = @_;
-       $self->{dbh} //= do {
+       $self->{dbh} // do {
                my $f = $self->{filename};
                $lock //= $self->lock_for_scope_fast;
                my $dbh = DBI->connect("dbi:SQLite:dbname=$f", '', '', {
@@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS kv (
        UNIQUE (k)
 )
 
-               $dbh;
+               $self->{dbh} = $dbh;
        }
 }
 
index b4db0582db79dfaa215f63b7f311133c64e93b80..a282784a257fb523ca3ae6a59567628709ecd5a6 100644 (file)
@@ -468,7 +468,7 @@ sub serve_mbox_range {
 
 sub news_www {
        my ($self) = @_;
-       $self->{news_www} ||= do {
+       $self->{news_www} //= do {
                require PublicInbox::NewsWWW;
                PublicInbox::NewsWWW->new($self->{pi_cfg});
        }
@@ -476,7 +476,7 @@ sub news_www {
 
 sub cgit {
        my ($self) = @_;
-       $self->{cgit} ||= do {
+       $self->{cgit} //= do {
                my $pi_cfg = $self->{pi_cfg};
 
                if (defined($pi_cfg->{'publicinbox.cgitrc'})) {
index b3476ab82e0922eb9c8f99ca5690016a30806571..eeb5e565039ec47c7a715e1ae2c6d993cbb2dbbf 100644 (file)
@@ -218,7 +218,7 @@ my %path_re_cache;
 sub path_info_raw ($) {
        my ($env) = @_;
        my $sn = $env->{SCRIPT_NAME};
-       my $re = $path_re_cache{$sn} ||= do {
+       my $re = $path_re_cache{$sn} //= do {
                $sn = '/'.$sn unless index($sn, '/') == 0;
                $sn =~ s!/\z!!;
                qr!\A(?:https?://[^/]+)?\Q$sn\E(/[^\?\#]+)!;
index 6d7c447fe6a2ecc7880cd6119e41c788dd966c96..aee78170c713df91ea1186264080fb32a7e2dbfa 100644 (file)
@@ -170,9 +170,9 @@ sub html_oneshot ($$;$) {
                'Content-Length' => undef ];
        bless $ctx, __PACKAGE__;
        $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
-       $ctx->{base_url} //= do {
+       $ctx->{base_url} // do {
                $ctx->zmore(html_top($ctx));
-               base_url($ctx);
+               $ctx->{base_url} = base_url($ctx);
        };
        $ctx->zmore($$sref) if $sref;
        my $bdy = $ctx->zflush(_html_end($ctx));