From 3517d8a6687cd37cb8c9009a78f16071d652254a Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Mon, 21 May 2018 11:38:41 -0400 Subject: almost working --- Bugzilla/CGI.pm | 9 +++++---- Bugzilla/Quantum.pm | 27 +++------------------------ Bugzilla/Quantum/CGI.pm | 2 -- Bugzilla/Quantum/Plugin/Glue.pm | 35 +++++++++++++++++++++++------------ Bugzilla/Quantum/Static.pm | 2 -- Bugzilla/Quantum/Template.pm | 3 +-- 6 files changed, 32 insertions(+), 46 deletions(-) (limited to 'Bugzilla') diff --git a/Bugzilla/CGI.pm b/Bugzilla/CGI.pm index d43a26eab..2dedbc5f3 100644 --- a/Bugzilla/CGI.pm +++ b/Bugzilla/CGI.pm @@ -561,10 +561,9 @@ sub header { } } my $headers = $self->SUPER::header(%headers) || ''; - warn "if (". $self->server_software." eq 'Bugzilla::Quantum::Plugin::Glue') {"; if ($self->server_software eq 'Bugzilla::Quantum::Plugin::Glue') { my $c = Bugzilla->request_cache->{mojo_controller}; - $c->res->headers(Mojo::Headers->new->parse($headers)) if $headers; + $c->res->headers->parse($headers); return ''; } else { @@ -671,10 +670,12 @@ sub send_cookie { sub redirect { my $self = shift; $self->{bz_redirecting} = 1; - warn "redirect: @_\n"; + use Carp; + carp "redirect @_\n"; if ($self->server_software eq 'Bugzilla::Quantum::Plugin::Glue') { my $c = Bugzilla->request_cache->{mojo_controller}; - $c->redirect_to(@_); + $self->SUPER::redirect(@_); + $c->redirect_to($c->res->headers->location); return ''; } else { diff --git a/Bugzilla/Quantum.pm b/Bugzilla/Quantum.pm index 3f197a508..9b98bffa2 100644 --- a/Bugzilla/Quantum.pm +++ b/Bugzilla/Quantum.pm @@ -36,34 +36,13 @@ sub startup { my $rest = compile_cgi('rest.cgi'); $self->plugin('Bugzilla::Quantum::Plugin::Glue'); - $self->plugin( - 'MountPSGI' => { - rewrite => 1, - '/rest' => $rest, - } - ); - $self->plugin( - 'MountPSGI' => { - rewrite => 1, - '/rest.cgi' => $rest, - } - ); - $self->plugin( - 'MountPSGI' => { - rewrite => 1, - '/xmlrpc.cgi' => compile_cgi('xmlrpc.cgi'), - } - ); - $self->plugin( - 'MountPSGI' => { -rewrite => 1, - '/jsonrpc.cgi' => compile_cgi('jsonrpc.cgi'), - } - ); + my $r = $self->routes; Bugzilla::Quantum::CGI->expose_routes($r); $r->any('/')->to('CGI#handle_index'); + $r->any('/rest')->to('CGI#handle_rest'); + $r->any('/rest/*path_info')->to('CGI#handle_rest'); $r->get( '/__lbheartbeat__' => sub { diff --git a/Bugzilla/Quantum/CGI.pm b/Bugzilla/Quantum/CGI.pm index 4d43158cc..fab2b145d 100644 --- a/Bugzilla/Quantum/CGI.pm +++ b/Bugzilla/Quantum/CGI.pm @@ -16,7 +16,6 @@ use Sub::Quote 2.005000; use Taint::Util qw(untaint); my %CGIS; -my %SKIP = ( 'xmlrpc.cgi' => 1, 'jsonrpc.cgi' => 1, 'rest.cgi' => 1); _load_all(); @@ -29,7 +28,6 @@ sub expose_routes { sub _load_all { foreach my $script (glob '*.cgi') { - next if $SKIP{$script}; my $name = _load_cgi($script); $CGIS{ $script } = $name; } diff --git a/Bugzilla/Quantum/Plugin/Glue.pm b/Bugzilla/Quantum/Plugin/Glue.pm index 2e3ecf4f0..17dc443c6 100644 --- a/Bugzilla/Quantum/Plugin/Glue.pm +++ b/Bugzilla/Quantum/Plugin/Glue.pm @@ -13,6 +13,7 @@ use Bugzilla::Constants; use Bugzilla::Quantum::Template; use Socket qw(AF_INET inet_aton); use Sys::Hostname; +use IO::String; sub register { my ( $self, $app, $conf ) = @_; @@ -23,7 +24,7 @@ sub register { $app->renderer->add_handler( 'bugzilla' => sub { my ( $renderer, $c, $output, $options ) = @_; - my %params; + my $vars = delete $c->stash->{vars}; # Helpers my %helper; @@ -31,16 +32,15 @@ sub register { my $sub = $renderer->helpers->{$method}; $helper{$method} = sub { $c->$sub(@_) }; } - $params{helper} = \%helper; + $vars->{helper} = \%helper; - # Stash values - $params{$_} = $c->stash->{$_} for grep {m/^\w+\z/} keys %{ $c->stash }; - $params{self} = $params{c} = $c; + # The controller + $vars->{c} = $c; my $name = $options->{template}; unless ($name =~ /\./) { $name = sprintf '%s.%s.tmpl', $options->{template}, $options->{format}; } - $template->process( $name, \%params, $output ) + $template->process( $name, $vars, $output ) or die $template->error; } ); @@ -48,21 +48,32 @@ sub register { $app->hook( around_dispatch => sub { my ($next, $c) = @_; + local %ENV = _ENV($c); + my $stdin = _STDIN($c); + my $stdout = ''; try { local $CGI::Compile::USE_REAL_EXIT = 0; - local %ENV = _ENV($c); - my $stdin = _STDIN($c); - warn "stdin path ", $stdin->path, "\n"; - local *STDIN; + local *STDIN; ## no critic (local) + local *STDOUT; open STDIN, '<', $stdin->path or die "STDIN @{[$stdin->path]}: $!" if -s $stdin->path; + open STDOUT, '>', \$stdout or die "STDOUT capture: $!"; + Bugzilla::init_page(); Bugzilla->request_cache->{mojo_controller} = $c; Bugzilla->template( Bugzilla::Quantum::Template->new( controller => $c, template => $template ) ); $next->(); + } + catch { + die $_ unless ref $_ eq 'ARRAY' && $_->[0] eq "EXIT\n" || /\bModPerl::Util::exit\b/; + } + finally { + if (length $stdout) { + warn "setting body\n"; + $c->res->body($stdout); + $c->rendered; + } Bugzilla::_cleanup; ## no critic (private) CGI::initialize_globals(); - } catch { - die $_ unless ref $_ eq 'ARRAY' && $_->[0] eq "EXIT\n" || /\bModPerl::Util::exit\b/; }; } ); diff --git a/Bugzilla/Quantum/Static.pm b/Bugzilla/Quantum/Static.pm index 2bd0555e2..2bb54990e 100644 --- a/Bugzilla/Quantum/Static.pm +++ b/Bugzilla/Quantum/Static.pm @@ -20,11 +20,9 @@ sub file { if (my ($legacy_rel) = $rel =~ $LEGACY_RE) { local $self->{paths} = [ bz_locations->{cgi_path} ]; - warn "legacy $legacy_rel\n"; return $self->SUPER::file($legacy_rel); } else { - warn "mojo $rel\n"; return $self->SUPER::file($rel); } } diff --git a/Bugzilla/Quantum/Template.pm b/Bugzilla/Quantum/Template.pm index ebae0cf9f..2442f1134 100644 --- a/Bugzilla/Quantum/Template.pm +++ b/Bugzilla/Quantum/Template.pm @@ -24,8 +24,7 @@ sub process { my ($self, $file, $vars, $output) = @_; if (@_ < 4) { - my $stash = $self->controller->stash; - $stash->{$_} = $vars->{$_} for keys %$vars; + $self->controller->stash->{vars} = $vars; $self->controller->render(template => $file, handler => 'bugzilla'); return 1; } -- cgit v1.2.3-24-g4f1b