From 416ba2fdab4f6de20ad7ec3656a057bb01b17339 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 10 Feb 2017 21:27:11 +0000 Subject: config: move try_cat function from inbox This allows RepoConfig to be independent of the PublicInbox::Inbox class. --- lib/PublicInbox/Config.pm | 10 ++++++++++ lib/PublicInbox/Inbox.pm | 15 +++------------ lib/PublicInbox/RepoConfig.pm | 3 +-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index f6275cdd..f2c40b13 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -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; diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm index 999f813b..05d04530 100644 --- a/lib/PublicInbox/Inbox.pm +++ b/lib/PublicInbox/Inbox.pm @@ -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; diff --git a/lib/PublicInbox/RepoConfig.pm b/lib/PublicInbox/RepoConfig.pm index 7a1b316c..fb1fd584 100644 --- a/lib/PublicInbox/RepoConfig.pm +++ b/lib/PublicInbox/RepoConfig.pm @@ -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} = -- cgit v1.2.3-24-ge0c7