From 62f28026e624ed30d620063a0fa92cbedb7f6673 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 10 Jan 2020 08:49:31 +0000 Subject: make Plack optional for non-WWW and non-httpd users Some users just want to run -mda, -watch, and/or -nntpd. Let them run just those without forcing them to pull in a bunch of dependencies. --- INSTALL | 10 +++++----- Makefile.PL | 10 ++++++++-- ci/deps.perl | 5 +++-- script/public-inbox-httpd | 15 +++++++++------ script/public-inbox.cgi | 15 +++++++++------ t/cgi.t | 1 + t/httpd-https.t | 2 +- t/psgi_attach.t | 6 ++---- t/psgi_bad_mids.t | 4 ++-- t/psgi_mount.t | 17 ++++++++--------- t/psgi_multipart_not.t | 2 +- t/psgi_search.t | 2 +- t/psgi_text.t | 5 ++--- t/psgi_v2.t | 2 +- t/solver_git.t | 2 +- t/view.t | 3 ++- xt/mem-msgview.t | 3 +-- xt/perf-msgview.t | 2 +- xt/solver.t | 2 +- 19 files changed, 59 insertions(+), 49 deletions(-) diff --git a/INSTALL b/INSTALL index 137c9a54..f834b49f 100644 --- a/INSTALL +++ b/INSTALL @@ -39,11 +39,6 @@ Beyond that, there is a long list of Perl modules required, starting with: pkg: p5-Email-MIME rpm: perl-Email-MIME -* Plack deb: libplack-perl - pkg: p5-Plack - rpm: perl-Plack, perl-Plack-Test, - (for HTML/Atom generation) - * URI::Escape deb: liburi-perl pkg: p5-URI rpm: perl-URI @@ -55,6 +50,11 @@ Where "deb" indicates package names for Debian-derived distributions, Numerous optional modules are likely to be useful as well: +* Plack deb: libplack-perl + pkg: p5-Plack + rpm: perl-Plack, perl-Plack-Test, + (for HTML/Atom generation) + - DBD::SQLite deb: libdbd-sqlite3-perl pkg: p5-DBD-SQLite rpm: perl-DBD-SQLite diff --git a/Makefile.PL b/Makefile.PL index 3492d965..6b20385a 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -127,8 +127,14 @@ WriteMakefile( # `perl5' on FreeBSD 'Encode' => 0, - # TODO: these should really be made optional... - 'Plack' => 0, + # Plack is needed for public-inbox-httpd and PublicInbox::WWW + # 'Plack' => 0, + + # Filesys::Notify::Simple is pulled in by Plack, but also + # needed by public-inbox-watch (for now) + 'Filesys::Notify::Simple' => 0, + + # TODO: this should really be made optional... 'URI::Escape' => 0, # We have more test dependencies, but do not force diff --git a/ci/deps.perl b/ci/deps.perl index 330ba2f3..08722e1c 100755 --- a/ci/deps.perl +++ b/ci/deps.perl @@ -9,7 +9,7 @@ my $usage = "$0 PKG_FMT PROFILE [PROFILE_MOD]"; my $pkg_fmt = shift; @ARGV or die $usage, "\n"; -my @test_essential = qw(Test::Simple Plack::Test); +my @test_essential = qw(Test::Simple); # we actually use Test::More # package profiles my $profiles = { @@ -27,7 +27,6 @@ my $profiles = { Encode ExtUtils::MakeMaker Filesys::Notify::Simple - Plack URI::Escape ), @test_essential ], @@ -40,6 +39,8 @@ my $profiles = { IO::Compress::Gzip Inline::C Net::Server + Plack + Plack::Test Plack::Middleware::Deflater Plack::Middleware::ReverseProxy Search::Xapian diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd index b2464f4e..09da505e 100755 --- a/script/public-inbox-httpd +++ b/script/public-inbox-httpd @@ -1,15 +1,18 @@ #!/usr/bin/perl -w -# Copyright (C) 2016-2019 all contributors +# Copyright (C) 2016-2020 all contributors # License: AGPL-3.0+ # # Standalone HTTP server for public-inbox. use strict; -use warnings; -use Plack::Util; use PublicInbox::Daemon; -use PublicInbox::HTTP; -use PublicInbox::HTTPD; -use Plack::Builder; +BEGIN { + for (qw(Plack::Builder Plack::Util)) { + eval("require $_") or die "E: Plack is required for $0\n"; + } + Plack::Builder->import; + require PublicInbox::HTTP; + require PublicInbox::HTTPD; +} my %httpds; my $app; my $refresh = sub { diff --git a/script/public-inbox.cgi b/script/public-inbox.cgi index c0e8e6c3..c766483a 100755 --- a/script/public-inbox.cgi +++ b/script/public-inbox.cgi @@ -1,14 +1,17 @@ #!/usr/bin/perl -w -# Copyright (C) 2014-2019 all contributors +# Copyright (C) 2014-2020 all contributors # License: AGPL-3.0+ or later # # Enables using PublicInbox::WWW as a CGI script use strict; -use warnings; -use Plack::Builder; -use Plack::Handler::CGI; -use PublicInbox::WWW; -BEGIN { PublicInbox::WWW->preload if $ENV{MOD_PERL} } +BEGIN { + for (qw(Plack::Builder Plack::Handler::CGI)) { + eval("require $_") or die "E: Plack is required for $0\n"; + } + Plack::Builder->import; + require PublicInbox::WWW; + PublicInbox::WWW->preload if $ENV{MOD_PERL}; +} my $www = PublicInbox::WWW->new; my $have_deflater = eval { require Plack::Middleware::Deflater; 1 }; my $app = builder { diff --git a/t/cgi.t b/t/cgi.t index 9f67d5c0..5760596c 100644 --- a/t/cgi.t +++ b/t/cgi.t @@ -7,6 +7,7 @@ use warnings; use Test::More; use Email::MIME; use PublicInbox::TestCommon; +require_mods(qw(Plack::Handler::CGI Plack::Util)); my ($tmpdir, $for_destroy) = tmpdir(); my $home = "$tmpdir/pi-home"; my $pi_home = "$home/.public-inbox"; diff --git a/t/httpd-https.t b/t/httpd-https.t index 265febe5..9ce060c8 100644 --- a/t/httpd-https.t +++ b/t/httpd-https.t @@ -6,7 +6,7 @@ use Test::More; use Socket qw(SOCK_STREAM IPPROTO_TCP SOL_SOCKET); use PublicInbox::TestCommon; # IO::Poll is part of the standard library, but distros may split them off... -require_mods(qw(IO::Socket::SSL IO::Poll)); +require_mods(qw(IO::Socket::SSL IO::Poll Plack::Util)); my $cert = 'certs/server-cert.pem'; my $key = 'certs/server-key.pem'; unless (-r $key && -r $cert) { diff --git a/t/psgi_attach.t b/t/psgi_attach.t index 0c3174bc..1ef5318c 100644 --- a/t/psgi_attach.t +++ b/t/psgi_attach.t @@ -9,15 +9,14 @@ my ($tmpdir, $for_destroy) = tmpdir(); my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; my $cfgpfx = "publicinbox.test"; -my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape); +my @mods = qw(HTTP::Request::Common Plack::Builder Plack::Test URI::Escape); require_mods(@mods); use_ok $_ foreach @mods; +use_ok 'PublicInbox::WWW'; use PublicInbox::Import; use PublicInbox::Git; use PublicInbox::Config; -use PublicInbox::WWW; use_ok 'PublicInbox::WwwAttach'; -use Plack::Builder; my $config = PublicInbox::Config->new(\<new($git, 'test', $addr); ok(length($dot_res) >= length($dot), 'dot almost matches'); $res = $cb->(GET('/test/Z%40B/4-any-filename.txt')); is($res->content, $dot_res, 'user-specified filename is OK'); - }); } done_testing(); diff --git a/t/psgi_bad_mids.t b/t/psgi_bad_mids.t index 5cdd249e..b568786d 100644 --- a/t/psgi_bad_mids.t +++ b/t/psgi_bad_mids.t @@ -5,12 +5,12 @@ use warnings; use Test::More; use PublicInbox::MIME; use PublicInbox::Config; -use PublicInbox::WWW; use PublicInbox::TestCommon; my @mods = qw(DBD::SQLite HTTP::Request::Common Plack::Test - URI::Escape Plack::Builder); + URI::Escape Plack::Builder PublicInbox::WWW); require_mods(@mods); use_ok($_) for @mods; +use_ok 'PublicInbox::WWW'; use_ok 'PublicInbox::V2Writable'; my ($inboxdir, $for_destroy) = tmpdir(); my $cfgpfx = "publicinbox.bad-mids"; diff --git a/t/psgi_mount.t b/t/psgi_mount.t index 751c13b7..d29df054 100644 --- a/t/psgi_mount.t +++ b/t/psgi_mount.t @@ -9,15 +9,14 @@ my ($tmpdir, $for_destroy) = tmpdir(); my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; my $cfgpfx = "publicinbox.test"; -my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape); +my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape + Plack::Builder Plack::App::URLMap); require_mods(@mods); use_ok $_ foreach @mods; +use_ok 'PublicInbox::WWW'; use PublicInbox::Import; use PublicInbox::Git; use PublicInbox::Config; -use PublicInbox::WWW; -use Plack::Builder; -use Plack::App::URLMap; my $config = PublicInbox::Config->new(\<new($config); -my $app = builder { - enable 'Head'; - mount '/a' => builder { sub { $www->call(@_) } }; - mount '/b' => builder { sub { $www->call(@_) } }; -}; +my $app = builder(sub { + enable('Head'); + mount('/a' => builder(sub { sub { $www->call(@_) } })); + mount('/b' => builder(sub { sub { $www->call(@_) } })); +}); test_psgi($app, sub { my ($cb) = @_; diff --git a/t/psgi_multipart_not.t b/t/psgi_multipart_not.t index 606151c4..47a691f6 100644 --- a/t/psgi_multipart_not.t +++ b/t/psgi_multipart_not.t @@ -5,12 +5,12 @@ use warnings; use Test::More; use Email::MIME; use PublicInbox::Config; -use PublicInbox::WWW; use PublicInbox::TestCommon; my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test URI::Escape Plack::Builder Plack::Test); require_mods(@mods); use_ok($_) for (qw(HTTP::Request::Common Plack::Test)); +use_ok 'PublicInbox::WWW'; use_ok 'PublicInbox::V2Writable'; my ($repo, $for_destroy) = tmpdir(); my $ibx = PublicInbox::Inbox->new({ diff --git a/t/psgi_search.t b/t/psgi_search.t index 534063f8..5310e5ab 100644 --- a/t/psgi_search.t +++ b/t/psgi_search.t @@ -7,13 +7,13 @@ use Email::MIME; use PublicInbox::Config; use PublicInbox::Inbox; use PublicInbox::InboxWritable; -use PublicInbox::WWW; use bytes (); # only for bytes::length use PublicInbox::TestCommon; my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test URI::Escape Plack::Builder); require_mods(@mods); use_ok($_) for (qw(HTTP::Request::Common Plack::Test)); +use_ok 'PublicInbox::WWW'; my ($tmpdir, $for_destroy) = tmpdir(); my $ibx = PublicInbox::Inbox->new({ diff --git a/t/psgi_text.t b/t/psgi_text.t index 757a1294..7cb7a165 100644 --- a/t/psgi_text.t +++ b/t/psgi_text.t @@ -9,15 +9,14 @@ my ($tmpdir, $for_destroy) = tmpdir(); my $maindir = "$tmpdir/main.git"; my $addr = 'test-public@example.com'; my $cfgpfx = "publicinbox.test"; -my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape); +my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape Plack::Builder); require_mods(@mods); use_ok $_ foreach @mods; use PublicInbox::Import; use PublicInbox::Git; use PublicInbox::Config; -use PublicInbox::WWW; +use_ok 'PublicInbox::WWW'; use_ok 'PublicInbox::WwwText'; -use Plack::Builder; my $config = PublicInbox::Config->new(\</dev/null`); plan skip_all => "$0 must be run from a git working tree" if $?; diff --git a/t/view.t b/t/view.t index 92962b15..38c12fcc 100644 --- a/t/view.t +++ b/t/view.t @@ -3,8 +3,9 @@ use strict; use warnings; use Test::More; +use PublicInbox::TestCommon; use Email::MIME; -use Plack::Util; +require_mods('Plack::Util'); use_ok 'PublicInbox::View'; use_ok 'PublicInbox::Config'; diff --git a/xt/mem-msgview.t b/xt/mem-msgview.t index 1ea0f559..0c3ad710 100644 --- a/xt/mem-msgview.t +++ b/xt/mem-msgview.t @@ -6,9 +6,8 @@ use IO::Handle; # ->flush use Fcntl qw(SEEK_SET); use PublicInbox::TestCommon; use PublicInbox::Tmpfile; -use PublicInbox::WWW; use Test::More; -my @mods = qw(DBD::SQLite BSD::Resource); +my @mods = qw(DBD::SQLite BSD::Resource PublicInbox::WWW); require_mods(@mods); use_ok($_) for @mods; my $lines = $ENV{NR_LINES} // 100000; diff --git a/xt/perf-msgview.t b/xt/perf-msgview.t index 11bd3a5d..8c9037ee 100644 --- a/xt/perf-msgview.t +++ b/xt/perf-msgview.t @@ -18,7 +18,7 @@ if (require_git(2.19, 1)) { warn "git <2.19, cat-file lacks --unordered, locality suffers\n"; } - +require_mods qw(Plack::Util); use_ok 'Plack::Util'; my $ibx = PublicInbox::Inbox->new({ inboxdir => $inboxdir, name => 'name' }); my $git = $ibx->git; diff --git a/xt/solver.t b/xt/solver.t index 4ff57fe7..5307e120 100644 --- a/xt/solver.t +++ b/xt/solver.t @@ -5,10 +5,10 @@ use strict; use Test::More; use PublicInbox::TestCommon; use PublicInbox::Config; # this relies on PI_CONFIG // ~/.public-inbox/config -use PublicInbox::WWW; my @psgi = qw(HTTP::Request::Common Plack::Test URI::Escape Plack::Builder); require_mods(qw(DBD::SQLite Search::Xapian), @psgi); use_ok($_) for @psgi; +use_ok 'PublicInbox::WWW'; my $cfg = PublicInbox::Config->new; my $www = PublicInbox::WWW->new($cfg); my $app = sub { -- cgit v1.2.3-24-ge0c7