]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
config: move try_cat function from inbox
authorEric Wong <e@80x24.org>
Fri, 10 Feb 2017 21:27:11 +0000 (21:27 +0000)
committerEric Wong <e@80x24.org>
Fri, 10 Feb 2017 21:27:11 +0000 (21:27 +0000)
This allows RepoConfig to be independent of the
PublicInbox::Inbox class.

lib/PublicInbox/Config.pm
lib/PublicInbox/Inbox.pm
lib/PublicInbox/RepoConfig.pm

index f6275cdd24663d2f5b3f8235d7e188a04863b923..f2c40b13ab73ce1f51cb3ed849bb2f1ed3e3b1f4 100644 (file)
@@ -167,4 +167,14 @@ sub _fill {
        $self->{-by_name}->{$name} = $rv;
 }
 
+sub try_cat {
+       my ($path) = @_;
+       my $rv = '';
+       if (open(my $fh, '<', $path)) {
+               local $/;
+               $rv = <$fh>;
+       }
+       $rv;
+}
+
 1;
index 999f813b6e31a8a7d89dc2bae27c3d134706072d..05d0453062e8da77e61b2edc91066f41d914a120 100644 (file)
@@ -6,6 +6,7 @@ package PublicInbox::Inbox;
 use strict;
 use warnings;
 use PublicInbox::Git;
+use PublicInbox::Config;
 use PublicInbox::MID qw(mid2path);
 use Devel::Peek qw(SvREFCNT);
 
@@ -102,21 +103,11 @@ sub search {
        };
 }
 
-sub try_cat {
-       my ($path) = @_;
-       my $rv = '';
-       if (open(my $fh, '<', $path)) {
-               local $/;
-               $rv = <$fh>;
-       }
-       $rv;
-}
-
 sub description {
        my ($self) = @_;
        my $desc = $self->{description};
        return $desc if defined $desc;
-       $desc = try_cat("$self->{mainrepo}/description");
+       $desc = PublicInbox::Config::try_cat("$self->{mainrepo}/description");
        local $/ = "\n";
        chomp $desc;
        $desc =~ s/\s+/ /smg;
@@ -128,7 +119,7 @@ sub cloneurl {
        my ($self) = @_;
        my $url = $self->{cloneurl};
        return $url if $url;
-       $url = try_cat("$self->{mainrepo}/cloneurl");
+       $url = PublicInbox::Config::try_cat("$self->{mainrepo}/cloneurl");
        my @url = split(/\s+/s, $url);
        local $/ = "\n";
        chomp @url;
index 7a1b316c8bc3eb2d33be18b6d9a615ec1e2871fd..fb1fd584cbeef7a420e9d666047a98f0f71dcf51 100644 (file)
@@ -3,7 +3,6 @@
 package PublicInbox::RepoConfig;
 use strict;
 use warnings;
-use PublicInbox::Inbox;
 use PublicInbox::Config;
 use PublicInbox::Repo;
 require PublicInbox::Hval;
@@ -54,7 +53,7 @@ sub lookup {
 
        # gitweb compatibility
        foreach my $key (qw(description cloneurl)) {
-               $rv->{$key} = PublicInbox::Inbox::try_cat("$path/$key");
+               $rv->{$key} = PublicInbox::Config::try_cat("$path/$key");
        }
 
        $rv->{desc_html} =