about summary refs log tree commit
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-02-04 04:44:23 +0000
committerEric Wong <e@yhbt.net>2020-02-04 21:39:54 +0000
commit6d4fced4acc79d745fcfae972d23c3e0849d277f (patch)
tree8d1489c9e1e35a1951563b04df3bf7643d3c4065
parentbf4d35dd2f6389e9aa4dc87fdfaef801fa5b9108 (diff)
downloadpublic-inbox-6d4fced4acc79d745fcfae972d23c3e0849d277f.tar.gz
inbox: simplify ->description and ->cloneurl
We can use "//=" from Perl 5.10 to simplify the logic for these
methods.  The use of chomp() in ->cloneurl was also unnecessary
since split(/\s+/s,...) already removes newlines.
-rw-r--r--lib/PublicInbox/Inbox.pm24
1 files changed, 9 insertions, 15 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index b76d4e5a..accfd974 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -219,25 +219,19 @@ sub try_cat {
 
 sub description {
         my ($self) = @_;
-        my $desc = $self->{description};
-        return $desc if defined $desc;
-        $desc = try_cat("$self->{inboxdir}/description");
-        local $/ = "\n";
-        chomp $desc;
-        $desc =~ s/\s+/ /smg;
-        $desc = '($INBOX_DIR/description missing)' if $desc eq '';
-        $self->{description} = $desc;
+        $self->{description} //= do {
+                my $desc = try_cat("$self->{inboxdir}/description");
+                local $/ = "\n";
+                chomp $desc;
+                $desc =~ s/\s+/ /smg;
+                $desc eq '' ? '($INBOX_DIR/description missing)' : $desc;
+        };
 }
 
 sub cloneurl {
         my ($self) = @_;
-        my $url = $self->{cloneurl};
-        return $url if $url;
-        $url = try_cat("$self->{inboxdir}/cloneurl");
-        my @url = split(/\s+/s, $url);
-        local $/ = "\n";
-        chomp @url;
-        $self->{cloneurl} = \@url;
+        $self->{cloneurl} //=
+                [ split(/\s+/s, try_cat("$self->{inboxdir}/cloneurl")) ];
 }
 
 sub base_url {