user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH 0/6] various cleanups around use/require
@ 2020-01-05 23:23 Eric Wong
  2020-01-05 23:23 ` [PATCH 1/6] hval: export prurl and add prototype Eric Wong
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Eric Wong @ 2020-01-05 23:23 UTC (permalink / raw)
  To: meta

We've accumulated some cruft over the years.  Lets get rid of
some of it and find places where we can help Perl figure more
stuff out at compile-time rather than run-time.

Eric Wong (6):
  hval: export prurl and add prototype
  view: update POSIX::strftime usage
  altid: use msgmap at compile time
  admin: do not lazy-load Inbox or Config packages
  treewide: "require" + "use" cleanup and docs
  syscall: modernize away from pre-Perl-5.6 conventions

 Makefile.PL                        |  2 +-
 lib/PublicInbox/Admin.pm           |  4 ++--
 lib/PublicInbox/AltId.pm           |  3 +--
 lib/PublicInbox/Config.pm          |  2 +-
 lib/PublicInbox/DS.pm              |  5 ++---
 lib/PublicInbox/Daemon.pm          |  2 +-
 lib/PublicInbox/Emergency.pm       |  2 +-
 lib/PublicInbox/ExtMsg.pm          |  5 ++---
 lib/PublicInbox/Filter/RubyLang.pm |  1 -
 lib/PublicInbox/Git.pm             |  2 +-
 lib/PublicInbox/GitHTTPBackend.pm  |  2 +-
 lib/PublicInbox/HTTP.pm            |  3 ++-
 lib/PublicInbox/HTTPD.pm           |  4 ++--
 lib/PublicInbox/Hval.pm            |  5 +++--
 lib/PublicInbox/Import.pm          |  2 +-
 lib/PublicInbox/Listener.pm        |  2 +-
 lib/PublicInbox/MboxGz.pm          |  1 -
 lib/PublicInbox/NNTPD.pm           |  2 +-
 lib/PublicInbox/NewsWWW.pm         |  3 ++-
 lib/PublicInbox/Search.pm          |  2 --
 lib/PublicInbox/SearchIdx.pm       |  2 +-
 lib/PublicInbox/SearchView.pm      |  6 +----
 lib/PublicInbox/SolverGit.pm       |  2 +-
 lib/PublicInbox/Spawn.pm           |  1 -
 lib/PublicInbox/Syscall.pm         | 35 ++++++++++++++----------------
 lib/PublicInbox/TLS.pm             |  2 --
 lib/PublicInbox/Tmpfile.pm         |  2 +-
 lib/PublicInbox/V2Writable.pm      |  2 +-
 lib/PublicInbox/View.pm            | 17 +++++++--------
 lib/PublicInbox/ViewDiff.pm        |  2 +-
 lib/PublicInbox/WatchMaildir.pm    |  2 +-
 lib/PublicInbox/WwwAtomStream.pm   |  2 +-
 lib/PublicInbox/WwwListing.pm      |  6 ++---
 lib/PublicInbox/WwwStream.pm       |  4 ++--
 lib/PublicInbox/Xapcmd.pm          |  2 +-
 script/public-inbox-convert        |  2 --
 script/public-inbox-edit           |  8 +++----
 script/public-inbox-init           |  4 ++--
 script/public-inbox-nntpd          |  4 ++--
 t/cgi.t                            |  2 --
 t/feed.t                           |  2 --
 41 files changed, 71 insertions(+), 92 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/6] hval: export prurl and add prototype
  2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
@ 2020-01-05 23:23 ` Eric Wong
  2020-01-05 23:23 ` [PATCH 2/6] view: update POSIX::strftime usage Eric Wong
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-01-05 23:23 UTC (permalink / raw)
  To: meta

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>)
 }
 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/6] view: update POSIX::strftime usage
  2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
  2020-01-05 23:23 ` [PATCH 1/6] hval: export prurl and add prototype Eric Wong
@ 2020-01-05 23:23 ` Eric Wong
  2020-01-05 23:23 ` [PATCH 3/6] altid: use msgmap at compile time Eric Wong
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-01-05 23:23 UTC (permalink / raw)
  To: meta

The POSIX module is always loaded, so import `strftime' into the
namespace so we can use it and take advantage of compile-time
arg checking.  While we're at it, update and reorder caller
functions to use prototypes, too.
---
 lib/PublicInbox/View.pm | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 0d6f3351..e5cc475f 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -16,7 +16,7 @@ use PublicInbox::Address;
 use PublicInbox::WwwStream;
 use PublicInbox::Reply;
 use PublicInbox::ViewDiff qw(flush_diff);
-require POSIX;
+use POSIX qw(strftime);
 use Time::Local qw(timegm);
 use PublicInbox::SearchMsg qw(subject_normalized);
 use constant COLS => 72;
@@ -207,6 +207,9 @@ sub nr_to_s ($$$) {
 	$nr == 1 ? "$nr $singular" : "$nr $plural";
 }
 
+# human-friendly format
+sub fmt_ts ($) { strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
+
 # this is already inside a <pre>
 sub index_entry {
 	my ($smsg, $ctx, $more) = @_;
@@ -925,8 +928,6 @@ sub missing_thread {
 	PublicInbox::ExtMsg::ext_msg($ctx);
 }
 
-sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
-
 sub dedupe_subject {
 	my ($prev_subj, $subj, $val) = @_;
 
@@ -1158,10 +1159,8 @@ sub dump_topics {
 	200;
 }
 
-sub ts2str ($) {
-	my ($ts) = @_;
-	POSIX::strftime('%Y%m%d%H%M%S', gmtime($ts));
-}
+# only for the t= query parameter passed to overview DB
+sub ts2str ($) { strftime('%Y%m%d%H%M%S', gmtime($_[0])) };
 
 sub str2ts ($) {
 	my ($yyyy, $mon, $dd, $hh, $mm, $ss) = unpack('A4A2A2A2A2A2', $_[0]);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/6] altid: use msgmap at compile time
  2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
  2020-01-05 23:23 ` [PATCH 1/6] hval: export prurl and add prototype Eric Wong
  2020-01-05 23:23 ` [PATCH 2/6] view: update POSIX::strftime usage Eric Wong
@ 2020-01-05 23:23 ` Eric Wong
  2020-01-05 23:23 ` [PATCH 4/6] admin: do not lazy-load Inbox or Config packages Eric Wong
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-01-05 23:23 UTC (permalink / raw)
  To: meta

AltId requires Msgmap to work, which requires SQLite.  Search
also requires SQLite3 (for Over), nowadays, so there's no reason
for us to lazy-load Msgmap and SQLite anymore.
---
 lib/PublicInbox/AltId.pm | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/PublicInbox/AltId.pm b/lib/PublicInbox/AltId.pm
index b4daaed2..6b03d603 100644
--- a/lib/PublicInbox/AltId.pm
+++ b/lib/PublicInbox/AltId.pm
@@ -13,6 +13,7 @@ package PublicInbox::AltId;
 use strict;
 use warnings;
 use URI::Escape qw(uri_unescape);
+use PublicInbox::Msgmap;
 
 # spec: TYPE:PREFIX:param1=value1&param2=value2&...
 # The PREFIX will be a searchable boolean prefix in Xapian
@@ -22,8 +23,6 @@ sub new {
 	my ($type, $prefix, $query) = split(/:/, $spec, 3);
 	$type eq 'serial' or die "non-serial not supported, yet\n";
 
-	require PublicInbox::Msgmap;
-
 	my %params = map {
 		my ($k, $v) = split(/=/, uri_unescape($_), 2);
 		$v = '' unless defined $v;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/6] admin: do not lazy-load Inbox or Config packages
  2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
                   ` (2 preceding siblings ...)
  2020-01-05 23:23 ` [PATCH 3/6] altid: use msgmap at compile time Eric Wong
@ 2020-01-05 23:23 ` 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
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-01-05 23:23 UTC (permalink / raw)
  To: meta

No point in lazy-loading these, since they're always loaded
anyways and would not have portability problems on systems with
minimal dependencies.
---
 lib/PublicInbox/Admin.pm  | 4 ++--
 lib/PublicInbox/Config.pm | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/Admin.pm b/lib/PublicInbox/Admin.pm
index 44b44b6e..1f1b133d 100644
--- a/lib/PublicInbox/Admin.pm
+++ b/lib/PublicInbox/Admin.pm
@@ -9,7 +9,8 @@ use warnings;
 use Cwd 'abs_path';
 use base qw(Exporter);
 our @EXPORT_OK = qw(resolve_repo_dir);
-require PublicInbox::Config;
+use PublicInbox::Config;
+use PublicInbox::Inbox;
 use PublicInbox::Spawn qw(popen_rd);
 
 sub resolve_repo_dir {
@@ -68,7 +69,6 @@ sub unconfigured_ibx ($$) {
 
 sub resolve_inboxes ($;$$) {
 	my ($argv, $opt, $cfg) = @_;
-	require PublicInbox::Inbox;
 	$opt ||= {};
 
 	$cfg //= eval { PublicInbox::Config->new };
diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index ffc31f83..cc8c1eaf 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -10,7 +10,7 @@
 package PublicInbox::Config;
 use strict;
 use warnings;
-require PublicInbox::Inbox;
+use PublicInbox::Inbox;
 use PublicInbox::Spawn qw(popen_rd);
 
 sub _array ($) { ref($_[0]) eq 'ARRAY' ? $_[0] : [ $_[0] ] }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/6] treewide: "require" + "use" cleanup and docs
  2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
                   ` (3 preceding siblings ...)
  2020-01-05 23:23 ` [PATCH 4/6] admin: do not lazy-load Inbox or Config packages Eric Wong
@ 2020-01-05 23:23 ` Eric Wong
  2020-01-05 23:23 ` [PATCH 6/6] syscall: modernize away from pre-Perl-5.6 conventions Eric Wong
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-01-05 23:23 UTC (permalink / raw)
  To: meta

There's a bunch of leftover "require" and "use" statements from
we no longer need to get rid of, along with some excessive
imports via "use".

IO::Handle usage isn't always obvious, so add comments
describing why a package loads it.  Along the same lines,
document the tmpdir support as the reason we depend on
File::Temp 0.19, even if every Perl 5.10.1+ user has it.

While we're at it, favor "use" over "require", since it it gives
us extra compile-time checking.
---
 Makefile.PL                        | 2 +-
 lib/PublicInbox/DS.pm              | 5 ++---
 lib/PublicInbox/Daemon.pm          | 2 +-
 lib/PublicInbox/Emergency.pm       | 2 +-
 lib/PublicInbox/ExtMsg.pm          | 1 -
 lib/PublicInbox/Filter/RubyLang.pm | 1 -
 lib/PublicInbox/Git.pm             | 2 +-
 lib/PublicInbox/GitHTTPBackend.pm  | 2 +-
 lib/PublicInbox/HTTP.pm            | 3 ++-
 lib/PublicInbox/HTTPD.pm           | 4 ++--
 lib/PublicInbox/Import.pm          | 2 +-
 lib/PublicInbox/Listener.pm        | 2 +-
 lib/PublicInbox/MboxGz.pm          | 1 -
 lib/PublicInbox/NNTPD.pm           | 2 +-
 lib/PublicInbox/Search.pm          | 2 --
 lib/PublicInbox/SearchIdx.pm       | 2 +-
 lib/PublicInbox/SearchView.pm      | 6 +-----
 lib/PublicInbox/SolverGit.pm       | 2 +-
 lib/PublicInbox/Spawn.pm           | 1 -
 lib/PublicInbox/TLS.pm             | 2 --
 lib/PublicInbox/Tmpfile.pm         | 2 +-
 lib/PublicInbox/V2Writable.pm      | 2 +-
 lib/PublicInbox/ViewDiff.pm        | 2 +-
 lib/PublicInbox/WatchMaildir.pm    | 2 +-
 lib/PublicInbox/WwwAtomStream.pm   | 2 +-
 lib/PublicInbox/Xapcmd.pm          | 2 +-
 script/public-inbox-convert        | 2 --
 script/public-inbox-edit           | 8 ++++----
 script/public-inbox-init           | 4 ++--
 script/public-inbox-nntpd          | 4 ++--
 t/cgi.t                            | 2 --
 t/feed.t                           | 2 --
 32 files changed, 31 insertions(+), 49 deletions(-)

diff --git a/Makefile.PL b/Makefile.PL
index b8c05cf7..3492d965 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -137,7 +137,7 @@ WriteMakefile(
 		# All Perl installs I know about have these, but RH-based
 		# distros make them separate even though 'perl' pulls them in
 		'File::Path' => 0,
-		'File::Temp' => '0.19',
+		'File::Temp' => '0.19', # for ->tmpdir support
 		'Getopt::Long' => 0,
 		'Exporter' => 0,
 		# ExtUtils::MakeMaker # this file won't run w/o it...
diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm
index 8f17f7fb..09dc3992 100644
--- a/lib/PublicInbox/DS.pm
+++ b/lib/PublicInbox/DS.pm
@@ -35,9 +35,8 @@ use fields ('sock',              # underlying socket
             'wbuf_off',  # offset into first element of wbuf to start writing at
             );
 
-use Errno  qw(EAGAIN EINVAL);
-use Carp   qw(croak confess carp);
-require File::Spec;
+use Errno qw(EAGAIN EINVAL);
+use Carp qw(confess carp);
 
 my $nextq; # queue for next_tick
 my $WaitPids; # list of [ pid, callback, callback_arg ]
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 9db472a1..292bc339 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -6,7 +6,7 @@ package PublicInbox::Daemon;
 use strict;
 use warnings;
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
-use IO::Handle;
+use IO::Handle; # ->autoflush
 use IO::Socket;
 use POSIX qw(WNOHANG :signal_h);
 use Socket qw(IPPROTO_TCP SOL_SOCKET);
diff --git a/lib/PublicInbox/Emergency.pm b/lib/PublicInbox/Emergency.pm
index 5ce75a79..8c0cc184 100644
--- a/lib/PublicInbox/Emergency.pm
+++ b/lib/PublicInbox/Emergency.pm
@@ -7,7 +7,7 @@ use strict;
 use warnings;
 use Fcntl qw(:DEFAULT SEEK_SET);
 use Sys::Hostname qw(hostname);
-use IO::Handle;
+use IO::Handle; # ->flush, ->autoflush
 
 sub new {
 	my ($class, $dir) = @_;
diff --git a/lib/PublicInbox/ExtMsg.pm b/lib/PublicInbox/ExtMsg.pm
index 549e4495..49fc1ac5 100644
--- a/lib/PublicInbox/ExtMsg.pm
+++ b/lib/PublicInbox/ExtMsg.pm
@@ -9,7 +9,6 @@ package PublicInbox::ExtMsg;
 use strict;
 use warnings;
 use PublicInbox::Hval qw(ascii_html prurl);
-use PublicInbox::MID qw/mid2path/;
 use PublicInbox::WwwStream;
 our $MIN_PARTIAL_LEN = 16;
 
diff --git a/lib/PublicInbox/Filter/RubyLang.pm b/lib/PublicInbox/Filter/RubyLang.pm
index 094ac1c2..3a8dd881 100644
--- a/lib/PublicInbox/Filter/RubyLang.pm
+++ b/lib/PublicInbox/Filter/RubyLang.pm
@@ -22,7 +22,6 @@ sub new {
 		$altid ||= $ibx->{altid}->[0];
 	}
 	if ($altid) {
-		require PublicInbox::MID; # mid_clean
 		require PublicInbox::AltId;
 		$self->{-altid} = PublicInbox::AltId->new($ibx, $altid, 1);
 	}
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 8d587469..6a527f82 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -10,7 +10,7 @@ package PublicInbox::Git;
 use strict;
 use warnings;
 use POSIX qw(dup2);
-require IO::Handle;
+use IO::Handle; # ->autoflush
 use PublicInbox::Spawn qw(spawn popen_rd);
 use PublicInbox::Tmpfile;
 use base qw(Exporter);
diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index d1132fb7..81ff23fc 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -7,7 +7,7 @@ package PublicInbox::GitHTTPBackend;
 use strict;
 use warnings;
 use Fcntl qw(:seek);
-use IO::Handle;
+use IO::Handle; # ->flush
 use HTTP::Date qw(time2str);
 use PublicInbox::Qspawn;
 use PublicInbox::Tmpfile;
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index d2f04ba5..1346901a 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -15,9 +15,10 @@ use fields qw(httpd env input_left remote_addr remote_port forward alive);
 use bytes (); # only for bytes::length
 use Fcntl qw(:seek);
 use Plack::HTTPParser qw(parse_http_request); # XS or pure Perl
+use Plack::Util;
 use HTTP::Status qw(status_message);
 use HTTP::Date qw(time2str);
-use IO::Handle;
+use IO::Handle; # ->write
 use PublicInbox::DS qw(msg_more);
 use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT);
 use PublicInbox::Tmpfile;
diff --git a/lib/PublicInbox/HTTPD.pm b/lib/PublicInbox/HTTPD.pm
index 47f5a01a..1331a91e 100644
--- a/lib/PublicInbox/HTTPD.pm
+++ b/lib/PublicInbox/HTTPD.pm
@@ -7,8 +7,8 @@ package PublicInbox::HTTPD;
 use strict;
 use warnings;
 use Plack::Util;
-require PublicInbox::HTTPD::Async;
-require PublicInbox::Daemon;
+use PublicInbox::HTTPD::Async;
+use PublicInbox::Daemon;
 
 sub pi_httpd_async { PublicInbox::HTTPD::Async->new(@_) }
 
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 20669ab9..572e9bb9 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -10,7 +10,7 @@ use strict;
 use warnings;
 use base qw(PublicInbox::Lock);
 use PublicInbox::Spawn qw(spawn);
-use PublicInbox::MID qw(mids mid_mime mid2path);
+use PublicInbox::MID qw(mids mid2path);
 use PublicInbox::Address;
 use PublicInbox::MsgTime qw(msg_timestamp msg_datestamp);
 use PublicInbox::ContentId qw(content_digest);
diff --git a/lib/PublicInbox/Listener.pm b/lib/PublicInbox/Listener.pm
index 821c3458..928d9301 100644
--- a/lib/PublicInbox/Listener.pm
+++ b/lib/PublicInbox/Listener.pm
@@ -8,7 +8,7 @@ use warnings;
 use base 'PublicInbox::DS';
 use Socket qw(SOL_SOCKET SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
 use fields qw(post_accept);
-require IO::Handle;
+use IO::Handle;
 use PublicInbox::Syscall qw(EPOLLIN EPOLLEXCLUSIVE EPOLLET);
 use Errno qw(EAGAIN ECONNABORTED EPERM);
 
diff --git a/lib/PublicInbox/MboxGz.pm b/lib/PublicInbox/MboxGz.pm
index 2b873451..08e3c846 100644
--- a/lib/PublicInbox/MboxGz.pm
+++ b/lib/PublicInbox/MboxGz.pm
@@ -6,7 +6,6 @@ use warnings;
 use Email::Simple;
 use PublicInbox::Hval qw/to_filename/;
 use PublicInbox::Mbox;
-use IO::Compress::Gzip;
 use Compress::Raw::Zlib qw(Z_FINISH Z_OK);
 my %OPT = (-WindowBits => 15 + 16, -AppendOutput => 1);
 
diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm
index 0f79f8f9..925691bc 100644
--- a/lib/PublicInbox/NNTPD.pm
+++ b/lib/PublicInbox/NNTPD.pm
@@ -7,7 +7,7 @@ package PublicInbox::NNTPD;
 use strict;
 use warnings;
 use Sys::Hostname;
-require PublicInbox::Config;
+use PublicInbox::Config;
 
 sub new {
 	my ($class) = @_;
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index aff3d48b..5c9dccb5 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -13,8 +13,6 @@ use constant YYYYMMDD => 1; # Date: header for searching in the WWW UI
 use constant DT => 2; # Date: YYYYMMDDHHMMSS
 
 use PublicInbox::SearchMsg;
-use PublicInbox::MIME;
-use PublicInbox::MID qw/id_compress/;
 use PublicInbox::Over;
 my $QP_FLAGS;
 our %X = map { $_ => 0 } qw(BoolWeight Database Enquire
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 0d983aab..f14809d2 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -12,7 +12,7 @@ use warnings;
 use base qw(PublicInbox::Search PublicInbox::Lock);
 use PublicInbox::MIME;
 use PublicInbox::InboxWritable;
-use PublicInbox::MID qw/mid_clean id_compress mid_mime mids_for_index/;
+use PublicInbox::MID qw/mid_clean mid_mime mids_for_index/;
 use PublicInbox::MsgIter;
 use Carp qw(croak);
 use POSIX qw(strftime);
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 6587d37f..0d2e71fd 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -10,10 +10,7 @@ use PublicInbox::SearchMsg;
 use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
 use PublicInbox::View;
 use PublicInbox::WwwAtomStream;
-use PublicInbox::MID qw(MID_ESC);
-use PublicInbox::MIME;
-require PublicInbox::Git;
-require PublicInbox::SearchThread;
+use PublicInbox::SearchThread;
 our $LIM = 200;
 my %rmap_inc;
 
@@ -350,7 +347,6 @@ package PublicInbox::SearchQuery;
 use strict;
 use warnings;
 use URI::Escape qw(uri_escape);
-use PublicInbox::Hval;
 use PublicInbox::MID qw(MID_ESC);
 
 sub new {
diff --git a/lib/PublicInbox/SolverGit.pm b/lib/PublicInbox/SolverGit.pm
index 5ac27988..8629f0da 100644
--- a/lib/PublicInbox/SolverGit.pm
+++ b/lib/PublicInbox/SolverGit.pm
@@ -11,7 +11,7 @@ package PublicInbox::SolverGit;
 use strict;
 use warnings;
 use 5.010_001;
-use File::Temp 0.19 ();
+use File::Temp 0.19 (); # 0.19 for ->newdir
 use Fcntl qw(SEEK_SET);
 use PublicInbox::Git qw(git_unquote git_quote);
 use PublicInbox::MsgIter qw(msg_iter msg_part_text);
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 6eea2b9c..1c74a596 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -15,7 +15,6 @@ use strict;
 use warnings;
 use base qw(Exporter);
 use Symbol qw(gensym);
-use IO::Handle;
 use PublicInbox::ProcessPipe;
 our @EXPORT_OK = qw/which spawn popen_rd/;
 sub RLIMITS () { qw(RLIMIT_CPU RLIMIT_CORE RLIMIT_DATA) }
diff --git a/lib/PublicInbox/TLS.pm b/lib/PublicInbox/TLS.pm
index 0b9a55df..1bbb229a 100644
--- a/lib/PublicInbox/TLS.pm
+++ b/lib/PublicInbox/TLS.pm
@@ -5,8 +5,6 @@
 package PublicInbox::TLS;
 use strict;
 use IO::Socket::SSL;
-require Carp;
-use Errno qw(EAGAIN);
 use PublicInbox::Syscall qw(EPOLLIN EPOLLOUT);
 
 sub err () { $SSL_ERROR }
diff --git a/lib/PublicInbox/Tmpfile.pm b/lib/PublicInbox/Tmpfile.pm
index 28e87f88..05f359d8 100644
--- a/lib/PublicInbox/Tmpfile.pm
+++ b/lib/PublicInbox/Tmpfile.pm
@@ -7,7 +7,7 @@ use base qw(Exporter);
 our @EXPORT = qw(tmpfile);
 use Fcntl qw(:DEFAULT);
 use Errno qw(EEXIST);
-require File::Spec;
+use File::Spec;
 
 # use tmpfile instead of open(..., '+>', undef) so we can get an
 # unlinked filename which makes sense when viewed with lsof
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index c614e20c..6021de44 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -18,7 +18,7 @@ use PublicInbox::OverIdx;
 use PublicInbox::Msgmap;
 use PublicInbox::Spawn qw(spawn);
 use PublicInbox::SearchIdx;
-use IO::Handle;
+use IO::Handle; # ->autoflush
 use File::Temp qw(tempfile);
 
 # an estimate of the post-packed size to the raw uncompressed size
diff --git a/lib/PublicInbox/ViewDiff.pm b/lib/PublicInbox/ViewDiff.pm
index 4d72eb48..10d71004 100644
--- a/lib/PublicInbox/ViewDiff.pm
+++ b/lib/PublicInbox/ViewDiff.pm
@@ -12,7 +12,7 @@ use warnings;
 use base qw(Exporter);
 our @EXPORT_OK = qw(flush_diff);
 use URI::Escape qw(uri_escape_utf8);
-use PublicInbox::Hval qw(ascii_html to_attr from_attr);
+use PublicInbox::Hval qw(ascii_html to_attr);
 use PublicInbox::Git qw(git_unquote);
 
 # keep track of state so we can avoid redundant HTML tags for
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index 7803b58a..8a8c1262 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -9,7 +9,7 @@ use warnings;
 use PublicInbox::MIME;
 use PublicInbox::Spawn qw(spawn);
 use PublicInbox::InboxWritable;
-use File::Temp 0.19 ();
+use File::Temp 0.19 (); # 0.19 for ->newdir
 use PublicInbox::Filter::Base qw(REJECT);
 use PublicInbox::Spamcheck;
 *maildir_path_load = *PublicInbox::InboxWritable::maildir_path_load;
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 84060cfa..9430dd97 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -13,7 +13,7 @@ use POSIX qw(strftime);
 use Digest::SHA qw(sha1_hex);
 use PublicInbox::Address;
 use PublicInbox::Hval qw(ascii_html);
-use PublicInbox::MID qw/mid_clean mid_escape/;
+use PublicInbox::MID qw(mid_escape);
 use PublicInbox::MsgTime qw(msg_timestamp);
 
 # called by PSGI server after getline:
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 544242a3..4871378e 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -6,7 +6,7 @@ use warnings;
 use PublicInbox::Spawn qw(which spawn);
 use PublicInbox::Over;
 use PublicInbox::SearchIdx;
-use File::Temp ();
+use File::Temp 0.19 (); # ->newdir
 use File::Path qw(remove_tree);
 use File::Basename qw(dirname);
 use POSIX ();
diff --git a/script/public-inbox-convert b/script/public-inbox-convert
index 9bee5e7a..633c4cf8 100755
--- a/script/public-inbox-convert
+++ b/script/public-inbox-convert
@@ -4,11 +4,9 @@
 use strict;
 use warnings;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
-use PublicInbox::MIME;
 use PublicInbox::InboxWritable;
 use PublicInbox::Config;
 use PublicInbox::V2Writable;
-use PublicInbox::Import;
 use PublicInbox::Spawn qw(spawn);
 use Cwd 'abs_path';
 use File::Copy 'cp'; # preserves permissions:
diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index 2a9f0531..e408c7bc 100755
--- a/script/public-inbox-edit
+++ b/script/public-inbox-edit
@@ -8,13 +8,13 @@ use strict;
 use warnings;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 use PublicInbox::AdminEdit;
-use File::Temp 0.19 ();
+use File::Temp 0.19 (); # 0.19 for TMPDIR
 use PublicInbox::ContentId qw(content_id);
 use PublicInbox::MID qw(mid_clean mids);
 PublicInbox::Admin::check_require('-index');
-require PublicInbox::MIME;
-require PublicInbox::InboxWritable;
-require PublicInbox::Import;
+use PublicInbox::MIME;
+use PublicInbox::InboxWritable;
+use PublicInbox::Import;
 
 my $usage = "$0 -m MESSAGE_ID [--all] [INBOX_DIRS]";
 my $opt = { verbose => 1, all => 0, -min_inbox_version => 2, raw => 0 };
diff --git a/script/public-inbox-init b/script/public-inbox-init
index da683657..34c93b47 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -14,8 +14,8 @@ EOF
 use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use PublicInbox::Admin;
 PublicInbox::Admin::require_or_die('-base');
-require PublicInbox::Config;
-require PublicInbox::InboxWritable;
+use PublicInbox::Config;
+use PublicInbox::InboxWritable;
 use File::Temp qw/tempfile/;
 use PublicInbox::Lock;
 use File::Basename qw/dirname/;
diff --git a/script/public-inbox-nntpd b/script/public-inbox-nntpd
index 3c4be191..27c33f04 100755
--- a/script/public-inbox-nntpd
+++ b/script/public-inbox-nntpd
@@ -5,9 +5,9 @@
 # Standalone NNTP server for public-inbox.
 use strict;
 use warnings;
-require PublicInbox::Daemon;
+use PublicInbox::Daemon;
 use PublicInbox::NNTP; # need to call import
-require PublicInbox::NNTPD;
+use PublicInbox::NNTPD;
 my $nntpd = PublicInbox::NNTPD->new;
 PublicInbox::Daemon::run('0.0.0.0:119',
 	sub { $nntpd->refresh_groups }, # refresh
diff --git a/t/cgi.t b/t/cgi.t
index 90543a7a..9f67d5c0 100644
--- a/t/cgi.t
+++ b/t/cgi.t
@@ -32,8 +32,6 @@ EOF
 	close $fh or die "close: $!\n";
 }
 
-use_ok 'PublicInbox::Git';
-use_ok 'PublicInbox::Import';
 use_ok 'PublicInbox::Inbox';
 use_ok 'PublicInbox::InboxWritable';
 use_ok 'PublicInbox::Config';
diff --git a/t/feed.t b/t/feed.t
index b2a94487..ec8a5a42 100644
--- a/t/feed.t
+++ b/t/feed.t
@@ -5,9 +5,7 @@ use warnings;
 use Test::More;
 use Email::MIME;
 use PublicInbox::Feed;
-use PublicInbox::Git;
 use PublicInbox::Import;
-use PublicInbox::Config;
 use PublicInbox::Inbox;
 my $have_xml_feed = eval { require XML::Feed; 1 };
 use PublicInbox::TestCommon;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 6/6] syscall: modernize away from pre-Perl-5.6 conventions
  2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
                   ` (4 preceding siblings ...)
  2020-01-05 23:23 ` [PATCH 5/6] treewide: "require" + "use" cleanup and docs Eric Wong
@ 2020-01-05 23:23 ` Eric Wong
  5 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-01-05 23:23 UTC (permalink / raw)
  To: meta

"use vars" was superseded by "our" in Perl 5.6, and we
can "use parent qw(Exporter)" in favor of manipulating
@ISA directly (or the bigger "use base ...");

While we're at it, avoid multiple invocations of constant->import
by passing a hashref as a "use" parameter.
---
 lib/PublicInbox/Syscall.pm | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/lib/PublicInbox/Syscall.pm b/lib/PublicInbox/Syscall.pm
index 487013d5..c66ea51b 100644
--- a/lib/PublicInbox/Syscall.pm
+++ b/lib/PublicInbox/Syscall.pm
@@ -13,42 +13,39 @@
 # License or the Artistic License, as specified in the Perl README file.
 package PublicInbox::Syscall;
 use strict;
+use parent qw(Exporter);
 use POSIX qw(ENOSYS SEEK_CUR);
 use Config;
 
-require Exporter;
-use vars qw(@ISA @EXPORT_OK %EXPORT_TAGS $VERSION);
-
-$VERSION     = "0.25";
-@ISA         = qw(Exporter);
-@EXPORT_OK   = qw(epoll_ctl epoll_create epoll_wait
+# $VERSION = '0.25'; # Sys::Syscall version
+our @EXPORT_OK = qw(epoll_ctl epoll_create epoll_wait
                   EPOLLIN EPOLLOUT EPOLLET
                   EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
                   EPOLLONESHOT EPOLLEXCLUSIVE
                   signalfd SFD_NONBLOCK);
-%EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait
+our %EXPORT_TAGS = (epoll => [qw(epoll_ctl epoll_create epoll_wait
                              EPOLLIN EPOLLOUT
                              EPOLL_CTL_ADD EPOLL_CTL_DEL EPOLL_CTL_MOD
                              EPOLLONESHOT EPOLLEXCLUSIVE)],
                 );
 
-use constant EPOLLIN       => 1;
-use constant EPOLLOUT      => 4;
-# use constant EPOLLERR      => 8;
-# use constant EPOLLHUP      => 16;
-# use constant EPOLLRDBAND   => 128;
-use constant EPOLLEXCLUSIVE => (1 << 28);
-use constant EPOLLONESHOT => (1 << 30);
-use constant EPOLLET => (1 << 31);
-use constant EPOLL_CTL_ADD => 1;
-use constant EPOLL_CTL_DEL => 2;
-use constant EPOLL_CTL_MOD => 3;
 use constant {
+	EPOLLIN => 1,
+	EPOLLOUT => 4,
+	# EPOLLERR => 8,
+	# EPOLLHUP => 16,
+	# EPOLLRDBAND => 128,
+	EPOLLEXCLUSIVE => (1 << 28),
+	EPOLLONESHOT => (1 << 30),
+	EPOLLET => (1 << 31),
+	EPOLL_CTL_ADD => 1,
+	EPOLL_CTL_DEL => 2,
+	EPOLL_CTL_MOD => 3,
+
 	SFD_CLOEXEC => 02000000,
 	SFD_NONBLOCK => 00004000,
 };
 
-
 our $loaded_syscall = 0;
 
 sub _load_syscall {

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-05 23:23 [PATCH 0/6] various cleanups around use/require Eric Wong
2020-01-05 23:23 ` [PATCH 1/6] hval: export prurl and add prototype Eric Wong
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

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