user/dev discussion of public-inbox itself
 help / color / Atom feed
From: Eric Wong <e@yhbt.net>
To: meta@public-inbox.org
Subject: [PATCH 1/6] hval: export prurl and add prototype
Date: Sun,  5 Jan 2020 23:23:31 +0000
Message-ID: <20200105232336.26023-2-e@yhbt.net> (raw)
In-Reply-To: <20200105232336.26023-1-e@yhbt.net>

This allows to do some compile-time checking and fills in a
missing "use" in PublicInbox::NewsWWW, allowing it to be used
standalone and independently of PublicInbox::WWW
---
 lib/PublicInbox/ExtMsg.pm     | 4 ++--
 lib/PublicInbox/Hval.pm       | 5 +++--
 lib/PublicInbox/NewsWWW.pm    | 3 ++-
 lib/PublicInbox/View.pm       | 4 ++--
 lib/PublicInbox/WwwListing.pm | 6 +++---
 lib/PublicInbox/WwwStream.pm  | 4 ++--
 6 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index 0f3e392d..549e4495 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -8,7 +8,7 @@
 package PublicInbox::ExtMsg;
 use strict;
 use warnings;
-use PublicInbox::Hval qw/ascii_html/;
+use PublicInbox::Hval qw(ascii_html prurl);
 use PublicInbox::MID qw/mid2path/;
 use PublicInbox::WwwStream;
 our $MIN_PARTIAL_LEN = 16;
@@ -172,7 +172,7 @@ sub ext_urls {
 		my $env = $ctx->{env};
 		my $e = "\nPerhaps try an external site:\n\n";
 		foreach my $url (@EXT_URL) {
-			my $u = PublicInbox::Hval::prurl($env, $url);
+			my $u = prurl($env, $url);
 			my $r = sprintf($u, $href);
 			my $t = sprintf($u, $html);
 			$e .= qq{<a\nhref="$r">$t</a>\n};
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index cd3a4df3..7e007027 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -10,7 +10,7 @@ use Encode qw(find_encoding);
 use PublicInbox::MID qw/mid_clean mid_escape/;
 use base qw/Exporter/;
 our @EXPORT_OK = qw/ascii_html obfuscate_addrs to_filename src_escape
-		to_attr from_attr/;
+		to_attr from_attr prurl/;
 my $enc_ascii = find_encoding('us-ascii');
 
 # safe-ish acceptable filename pattern for portability
@@ -84,7 +84,8 @@ sub raw {
 	}
 }
 
-sub prurl {
+# returns a protocol-relative URL string
+sub prurl ($$) {
 	my ($env, $u) = @_;
 	if (ref($u) eq 'ARRAY') {
 		my $h = $env->{HTTP_HOST} // $env->{SERVER_NAME};
diff --git a/lib/PublicInbox/NewsWWW.pm b/lib/PublicInbox/NewsWWW.pm
index ee11a089..be1d43ef 100644
--- a/lib/PublicInbox/NewsWWW.pm
+++ b/lib/PublicInbox/NewsWWW.pm
@@ -10,6 +10,7 @@ use strict;
 use warnings;
 use PublicInbox::Config;
 use PublicInbox::MID qw(mid_escape);
+use PublicInbox::Hval qw(prurl);
 
 sub new {
 	my ($class, $pi_config) = @_;
@@ -48,7 +49,7 @@ sub call {
 	my ($ng, $article) = @parts;
 	my $pi_config = $self->{pi_config};
 	if (my $ibx = $pi_config->lookup_newsgroup($ng)) {
-		my $url = PublicInbox::Hval::prurl($env, $ibx->{url});
+		my $url = prurl($env, $ibx->{url});
 		my $code = 301;
 		if (defined $article && $article =~ /\A[0-9]+\z/) {
 			my $mid = eval { $ibx->mm->mid_for($article) };
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index c38a1289..0d6f3351 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -8,7 +8,7 @@ use strict;
 use warnings;
 use bytes (); # only for bytes::length
 use PublicInbox::MsgTime qw(msg_datestamp);
-use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
+use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl);
 use PublicInbox::Linkify;
 use PublicInbox::MID qw/id_compress mid_escape mids mids_for_index references/;
 use PublicInbox::MsgIter;
@@ -122,7 +122,7 @@ sub msg_reply {
 	my $info = '';
 	my $ibx = $ctx->{-inbox};
 	if (my $url = $ibx->{infourl}) {
-		$url = PublicInbox::Hval::prurl($ctx->{env}, $url);
+		$url = prurl($ctx->{env}, $url);
 		$info = qq(\n  List information: <a\nhref="$url">$url</a>\n);
 	}
 
diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm
index 4f076b7d..a52dba11 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -6,7 +6,7 @@
 package PublicInbox::WwwListing;
 use strict;
 use warnings;
-use PublicInbox::Hval qw(ascii_html);
+use PublicInbox::Hval qw(ascii_html prurl);
 use PublicInbox::Linkify;
 use PublicInbox::View;
 use PublicInbox::Inbox;
@@ -84,13 +84,13 @@ sub new {
 sub ibx_entry {
 	my ($mtime, $ibx, $env) = @_;
 	my $ts = PublicInbox::View::fmt_ts($mtime);
-	my $url = PublicInbox::Hval::prurl($env, $ibx->{url});
+	my $url = prurl($env, $ibx->{url});
 	my $tmp = <<"";
 * $ts - $url
   ${\$ibx->description}
 
 	if (defined(my $info_url = $ibx->{infourl})) {
-		$tmp .= '  ' . PublicInbox::Hval::prurl($env, $info_url) . "\n";
+		$tmp .= '  ' . prurl($env, $info_url) . "\n";
 	}
 	$tmp;
 }
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 0f4f55d0..8f5a6526 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -9,7 +9,7 @@
 package PublicInbox::WwwStream;
 use strict;
 use warnings;
-use PublicInbox::Hval qw(ascii_html);
+use PublicInbox::Hval qw(ascii_html prurl);
 our $TOR_URL = 'https://www.torproject.org/';
 our $CODE_URL = 'https://public-inbox.org/public-inbox.git';
 
@@ -78,7 +78,7 @@ sub _html_top ($) {
 
 sub code_footer ($) {
 	my ($env) = @_;
-	my $u = PublicInbox::Hval::prurl($env, $CODE_URL);
+	my $u = prurl($env, $CODE_URL);
 	qq(AGPL code for this site: git clone <a\nhref="$u">$u</a>)
 }
 

  reply index

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
2020-01-05 23:23 ` Eric Wong [this message]
2020-01-05 23:23 ` [PATCH 2/6] view: update POSIX::strftime usage Eric Wong
2020-01-05 23:23 ` [PATCH 3/6] altid: use msgmap at compile time Eric Wong
2020-01-05 23:23 ` [PATCH 4/6] admin: do not lazy-load Inbox or Config packages Eric Wong
2020-01-05 23:23 ` [PATCH 5/6] treewide: "require" + "use" cleanup and docs Eric Wong
2020-01-05 23:23 ` [PATCH 6/6] syscall: modernize away from pre-Perl-5.6 conventions Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200105232336.26023-2-e@yhbt.net \
    --to=e@yhbt.net \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git