]> Sergey Matveev's repositories - public-inbox.git/commitdiff
make Plack optional for non-WWW and non-httpd users
authorEric Wong <e@yhbt.net>
Fri, 10 Jan 2020 08:49:31 +0000 (08:49 +0000)
committerEric Wong <e@yhbt.net>
Sat, 11 Jan 2020 21:16:26 +0000 (21:16 +0000)
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.

19 files changed:
INSTALL
Makefile.PL
ci/deps.perl
script/public-inbox-httpd
script/public-inbox.cgi
t/cgi.t
t/httpd-https.t
t/psgi_attach.t
t/psgi_bad_mids.t
t/psgi_mount.t
t/psgi_multipart_not.t
t/psgi_search.t
t/psgi_text.t
t/psgi_v2.t
t/solver_git.t
t/view.t
xt/mem-msgview.t
xt/perf-msgview.t
xt/solver.t

diff --git a/INSTALL b/INSTALL
index 137c9a54b1601dc6e0d75a29e5c9ff7816062204..f834b49f01fe5107415a813fdcf83e62ea7c77af 100644 (file)
--- 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
index 3492d9653ece202ae1061970798828f4c9a3d78e..6b20385a56838708719ad44cea75ed3c2e523de9 100644 (file)
@@ -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
index 330ba2f32fa43140bcde89733093afbb8bc1acfb..08722e1c41902275704a85b97f99be258192831d 100755 (executable)
@@ -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
index b2464f4efc0d31be9909c872c3969353e33768c6..09da505e5028952a60551f7bd2ffc25cf57c7780 100755 (executable)
@@ -1,15 +1,18 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # 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 {
index c0e8e6c329b792333941f6f8d975fcb77d7dfb3e..c766483a208cacb4dceec28e8c80795447591ed6 100755 (executable)
@@ -1,14 +1,17 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2014-2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2014-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ or later <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # 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 9f67d5c0bd0004d89275c0d4e22a615993c3bc48..5760596ca66cda6fcf61f734f41a6c04da6615f4 100644 (file)
--- 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";
index 265febe5ea843f7afb2691ab43657c1a5c8aafde..9ce060c8c7c1c8865648f92c381704eabac941c0 100644 (file)
@@ -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) {
index 0c3174bc241c7c257567ea0905307c876316ae50..1ef5318cd4799aab1a5469b7884572acaa4faae4 100644 (file)
@@ -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(\<<EOF);
 $cfgpfx.address=$addr
 $cfgpfx.inboxdir=$maindir
@@ -108,7 +107,6 @@ my $im = PublicInbox::Import->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();
index 5cdd249e7ea3608fdc0c45da2de85e826d4c32cd..b568786dfb4c3241810477a11402feee9e744eec 100644 (file)
@@ -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";
index 751c13b715a0c8616a79e7e5b0ef58eac3da8497..d29df054586d477fb598558a82adcd065340c500 100644 (file)
@@ -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(\<<EOF);
 $cfgpfx.address=$addr
 $cfgpfx.inboxdir=$maindir
@@ -41,11 +40,11 @@ EOF
 }
 
 my $www = PublicInbox::WWW->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) = @_;
index 606151c49d6006a5e401a07c89ba29242c8f0cff..47a691f67c98be1a22ea64ef178ce8073779f1f0 100644 (file)
@@ -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({
index 534063f8ed5206bbd8229dd92699973c2270cde1..5310e5aba9553bbabf252da82c97d3a520c9165e 100644 (file)
@@ -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({
index 757a1294ba6d6d0312da3aa7154e02133adfb9e0..7cb7a165cdc226998935f35a8eee8bf506baa5dd 100644 (file)
@@ -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(\<<EOF);
 $cfgpfx.address=$addr
 $cfgpfx.inboxdir=$maindir
index 8c619cee08189ef00da350cfcf43ab2382268e7f..2ecd7458e48eee28467194faa01f14161449397e 100644 (file)
@@ -7,11 +7,11 @@ use PublicInbox::TestCommon;
 require_git(2.6);
 use PublicInbox::MIME;
 use PublicInbox::Config;
-use PublicInbox::WWW;
 use PublicInbox::MID qw(mids);
 require_mods(qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
                URI::Escape Plack::Builder));
 use_ok($_) for (qw(HTTP::Request::Common Plack::Test));
+use_ok 'PublicInbox::WWW';
 use_ok 'PublicInbox::V2Writable';
 my ($inboxdir, $for_destroy) = tmpdir();
 my $ibx = {
index 67ae02e63877131a461388bc04f2484c326100b2..77fa1e09691d01cf0b35531528f37b7c1adc3966 100644 (file)
@@ -7,7 +7,7 @@ use Cwd qw(abs_path);
 use PublicInbox::TestCommon;
 require_git(2.6);
 use PublicInbox::Spawn qw(spawn);
-require_mods(qw(DBD::SQLite Search::Xapian));
+require_mods(qw(DBD::SQLite Search::Xapian Plack::Util));
 chomp(my $git_dir = `git rev-parse --git-dir 2>/dev/null`);
 plan skip_all => "$0 must be run from a git working tree" if $?;
 
index 92962b15f2007eeac9b3df438508edc5be94ea2f..38c12fcc1fda8bddd64be81dba0c17920228142b 100644 (file)
--- 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';
 
index 1ea0f559ee0a329482bba0db94524843a1dc8332..0c3ad71070bb595f59811f1b3f070ee377c11918 100644 (file)
@@ -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;
index 11bd3a5d64657ff8d476e1273fd38d5f71490265..8c9037ee215e019dd9664a4c694d5b7034eae627 100644 (file)
@@ -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;
index 4ff57fe75d4de1fe60443f64add4e03e7f5075a4..5307e1201cb96251b284eabf748d620aed485659 100644 (file)
@@ -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 {