diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-04-04 05:05:04 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-06-28 22:41:54 +0200 |
commit | ed6d5cdaaeac6422e5933e4e8138b481e35ab4f3 (patch) | |
tree | 821e7a1330326e5d9630560076049bce01f3c3d6 | |
parent | 5d6d68697dceec6a8c5a8947118abe527ad09ba1 (diff) | |
download | bugzilla-ed6d5cdaaeac6422e5933e4e8138b481e35ab4f3.tar.gz bugzilla-ed6d5cdaaeac6422e5933e4e8138b481e35ab4f3.tar.xz |
initial proof of concept of mojolicious inside bmo
-rw-r--r-- | Bugzilla.pm | 12 | ||||
-rw-r--r-- | Bugzilla/CGI/Mojo.pm | 29 | ||||
-rw-r--r-- | Bugzilla/Constants.pm | 2 | ||||
-rw-r--r-- | Bugzilla/Install/Filesystem.pm | 1 | ||||
-rw-r--r-- | Bugzilla/ModPerl.pm | 7 | ||||
-rwxr-xr-x | new.psgi | 45 |
6 files changed, 95 insertions, 1 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm index cf22ecc32..265235be5 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -234,7 +234,14 @@ sub extensions { } sub cgi { - return request_cache->{cgi} ||= new Bugzilla::CGI(); + my ( undef, $cgi ) = @_; + + if ( defined $cgi ) { + return request_cache->{cgi} = $cgi; + } + else { + return request_cache->{cgi} ||= Bugzilla::CGI->new; + } } sub input_params { @@ -568,6 +575,9 @@ sub usage_mode { elsif ($newval == USAGE_MODE_REST) { $class->error_mode(ERROR_MODE_REST); } + elsif ($newval == USAGE_MODE_MOJO) { + $class->error_mode(ERROR_MODE_DIE); + } else { ThrowCodeError('usage_mode_invalid', {'invalid_usage_mode', $newval}); diff --git a/Bugzilla/CGI/Mojo.pm b/Bugzilla/CGI/Mojo.pm new file mode 100644 index 000000000..0ae12f976 --- /dev/null +++ b/Bugzilla/CGI/Mojo.pm @@ -0,0 +1,29 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::CGI::Mojo; +use 5.10.1; +use Moo; + +has 'controller' => ( + is => 'ro', + handles => [qw(param cookie)], +); + +sub script_name { + my ($self) = @_; + + return $self->controller->req->env->{SCRIPT_NAME}; +} + +sub Vars { + my ($self) = @_; + + return $self->controller->req->query_params->to_hash; +} + +1;
\ No newline at end of file diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm index 3aa7b0fa4..8ef776f96 100644 --- a/Bugzilla/Constants.pm +++ b/Bugzilla/Constants.pm @@ -130,6 +130,7 @@ use Memoize; USAGE_MODE_JSON USAGE_MODE_TEST USAGE_MODE_REST + USAGE_MODE_MOJO ERROR_MODE_WEBPAGE ERROR_MODE_DIE @@ -487,6 +488,7 @@ use constant USAGE_MODE_EMAIL => 3; use constant USAGE_MODE_JSON => 4; use constant USAGE_MODE_TEST => 5; use constant USAGE_MODE_REST => 6; +use constant USAGE_MODE_MOJO => 7; # Error modes. Default set by Bugzilla->usage_mode (so ERROR_MODE_WEBPAGE # usually). Use with Bugzilla->error_mode. diff --git a/Bugzilla/Install/Filesystem.pm b/Bugzilla/Install/Filesystem.pm index 003be22e4..739ea9a0a 100644 --- a/Bugzilla/Install/Filesystem.pm +++ b/Bugzilla/Install/Filesystem.pm @@ -214,6 +214,7 @@ sub FILESYSTEM { # users to be able to cron them or otherwise run # them as a secure user, like the webserver owner. '*.cgi' => { perms => WS_EXECUTE }, + '*.psgi' => { perms => CGI_READ }, 'whineatnews.pl' => { perms => WS_EXECUTE }, 'collectstats.pl' => { perms => WS_EXECUTE }, 'importxml.pl' => { perms => WS_EXECUTE }, diff --git a/Bugzilla/ModPerl.pm b/Bugzilla/ModPerl.pm index 19cd1128f..6f7ed22e9 100644 --- a/Bugzilla/ModPerl.pm +++ b/Bugzilla/ModPerl.pm @@ -109,6 +109,13 @@ ErrorDocument 500 /errors/500.html require valid-user </Location> +<Location /new> + SetHandler perl-script + PerlResponseHandler Plack::Handler::Apache2 + PerlSetEnv MOJO_HOME [% cgi_path %] + PerlSetVar psgi_app [% cgi_path %]/new.psgi +</Location> + # directory rules for all the other places we have .htaccess files [% FOREACH htaccess IN htaccess_files %] # from [% htaccess.file %] diff --git a/new.psgi b/new.psgi new file mode 100755 index 000000000..8f1484d91 --- /dev/null +++ b/new.psgi @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +use Mojolicious::Lite; +use Bugzilla::Constants; +use Bugzilla::CGI::Mojo; +use Try::Tiny; + +plugin 'PODRenderer'; + + +app->hook( + around_dispatch => sub { + my ($next, $c) = @_; + try { + local %{ Bugzilla->request_cache } = (); + Bugzilla->usage_mode(USAGE_MODE_MOJO); + Bugzilla->cgi( Bugzilla::CGI::Mojo->new(controller => $c) ); + $next->(); + } catch { + die $_ unless /\bModPerl::Util::exit\b/; + }; + } +); + +get '/' => sub { + my $c = shift; + my $user = Bugzilla->login(LOGIN_OPTIONAL); + $c->render( template => 'index', user => $user ); +}; + +app->start; +__DATA__ + +@@ index.html.ep +% layout 'default'; +% title 'Welcome'; + +<p>Hello, <%= $user->name %> <<%= $user->email %>> +</p> + +@@ layouts/default.html.ep +<!DOCTYPE html> +<html> + <head><title><%= title %></title></head> + <body><%= content %></body> +</html> |