user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
 Warning: Initial query:
 %22www: make interface more OO%22
 returned no results, used:
 "www: make interface more OO"
 instead

Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 2/2] www: make interface more OO
  2016-02-25  3:10  6% [PATCH 0/2] remove CGI.pm support Eric Wong
@ 2016-02-25  3:10  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-02-25  3:10 UTC (permalink / raw)
  To: meta

This allows multiple instances the WWW app from
running within the same process space
---
 examples/public-inbox.psgi |  7 ++-----
 lib/PublicInbox/WWW.pm     | 24 ++++++++++++++++++------
 public-inbox-httpd         |  7 ++-----
 public-inbox.cgi           |  7 ++-----
 4 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/examples/public-inbox.psgi b/examples/public-inbox.psgi
index c4a8903..e3e4215 100644
--- a/examples/public-inbox.psgi
+++ b/examples/public-inbox.psgi
@@ -10,7 +10,7 @@ PublicInbox::WWW->preload;
 use Plack::Request;
 use Plack::Builder;
 my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
-
+my $www = PublicInbox::WWW->new;
 builder {
 	enable 'Chunked';
 	if ($have_deflater) {
@@ -25,8 +25,5 @@ builder {
 	# See Plack::Middleware::ReverseProxy documentation for details
 	# enable 'ReverseProxy';
 	enable 'Head';
-	sub {
-		my $req = Plack::Request->new(@_);
-		PublicInbox::WWW::run($req, $req->method);
-	}
+	sub { $www->call(@_) };
 }
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 651c19e..e87e559 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -22,14 +22,26 @@ use PublicInbox::GitHTTPBackend;
 our $LISTNAME_RE = qr!\A/([\w\.\-]+)!;
 our $MID_RE = qr!([^/]+)!;
 our $END_RE = qr!(f/|T/|t/|R/|t\.mbox(?:\.gz)?|t\.atom|raw|)!;
-our $pi_config;
 
-sub run {
-	my ($cgi, $method) = @_;
+sub new {
+	my ($class, $pi_config) = @_;
 	$pi_config ||= PublicInbox::Config->new;
-	my $ctx = { cgi => $cgi, pi_config => $pi_config };
+	bless { pi_config => $pi_config }, $class;
+}
+
+# backwards compatibility, do not use
+sub run {
+	my ($req, $method) = @_;
+	PublicInbox::WWW->new->call($req->env);
+}
+
+sub call {
+	my ($self, $env) = @_;
+	my $cgi = Plack::Request->new($env);
+	my $ctx = { cgi => $cgi, pi_config => $self->{pi_config} };
 	my $path_info = $cgi->path_info;
 
+	my $method = $cgi->method;
 	if ($method eq 'POST' &&
 		 $path_info =~ m!$LISTNAME_RE/(git-upload-pack)\z!) {
 		my $path = $2;
@@ -107,7 +119,7 @@ sub r { [ $_[0], ['Content-Type' => 'text/plain'], [ join(' ', @_, "\n") ] ] }
 # returns undef if valid, array ref response if invalid
 sub invalid_list {
 	my ($ctx, $listname) = @_;
-	my $git_dir = $pi_config->get($listname, "mainrepo");
+	my $git_dir = $ctx->{pi_config}->get($listname, "mainrepo");
 	if (defined $git_dir) {
 		$ctx->{git_dir} = $git_dir;
 		$ctx->{git} = PublicInbox::Git->new($git_dir);
@@ -264,7 +276,7 @@ sub footer {
 			join("\n", map { "\t$_" } @urls);
 	}
 
-	my $addr = $pi_config->get($listname, 'address');
+	my $addr = $ctx->{pi_config}->get($listname, 'address');
 	if (ref($addr) eq 'ARRAY') {
 		$addr = $addr->[0]; # first address is primary
 	}
diff --git a/public-inbox-httpd b/public-inbox-httpd
index 6436bd7..3635c9a 100644
--- a/public-inbox-httpd
+++ b/public-inbox-httpd
@@ -24,6 +24,7 @@ my $refresh = sub {
 "$0 runs in /, command-line paths must be absolute\n";
 		}
 	} else {
+		my $www = PublicInbox::WWW->new;
 		$app = eval {
 			my $deflate_types = eval {
 				require Plack::Middleware::Deflater;
@@ -37,11 +38,7 @@ my $refresh = sub {
 						content_type => $deflate_types
 				}
 				enable 'Head';
-				sub {
-					my $req = Plack::Request->new(@_);
-					PublicInbox::WWW::run($req,
-							$req->method);
-				};
+				sub { $www->call(@_) };
 			};
 		};
 	}
diff --git a/public-inbox.cgi b/public-inbox.cgi
index e73e23c..ee9510c 100755
--- a/public-inbox.cgi
+++ b/public-inbox.cgi
@@ -11,7 +11,7 @@ use Plack::Request;
 use Plack::Handler::CGI;
 use PublicInbox::WWW;
 BEGIN { PublicInbox::WWW->preload if $ENV{MOD_PERL} }
-
+my $www = PublicInbox::WWW->new;
 my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
 my $app = builder {
 	if ($have_deflater) {
@@ -27,9 +27,6 @@ my $app = builder {
 	# enable 'ReverseProxy';
 
 	enable 'Head';
-	sub {
-		my $req = Plack::Request->new(@_);
-		PublicInbox::WWW::run($req, $req->method);
-	}
+	sub { $www->call(@_) };
 };
 Plack::Handler::CGI->new->run($app);
-- 
EW


^ permalink raw reply related	[relevance 7%]

* [PATCH 0/2] remove CGI.pm support
@ 2016-02-25  3:10  6% Eric Wong
  2016-02-25  3:10  7% ` [PATCH 2/2] www: make interface more OO Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-02-25  3:10 UTC (permalink / raw)
  To: meta

We probably never should've supported CGI.pm in the first place,
but oh well.  We'll probably need to support running as .cgi
forever...

Eric Wong (2):
      remove direct CGI.pm support
      www: make interface more OO

 INSTALL                           |  5 +--
 Makefile.PL                       |  2 +-
 examples/public-inbox.psgi        |  7 ++--
 lib/PublicInbox/ExtMsg.pm         | 11 ++----
 lib/PublicInbox/Feed.pm           |  9 +----
 lib/PublicInbox/GitHTTPBackend.pm |  6 ++--
 lib/PublicInbox/WWW.pm            | 48 ++++++++++++-------------
 public-inbox-httpd                |  7 ++--
 public-inbox.cgi                  | 76 ++++++++++++---------------------------
 9 files changed, 56 insertions(+), 115 deletions(-)

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-02-25  3:10  6% [PATCH 0/2] remove CGI.pm support Eric Wong
2016-02-25  3:10  7% ` [PATCH 2/2] www: make interface more OO Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).