diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-07-23 17:25:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-23 17:25:43 +0200 |
commit | 345e686485e484e087ea58c988e4831209c39554 (patch) | |
tree | 6888ff14ec3d34cfe21d64d520421ba94918a25b | |
parent | e8c0dfe232ce1efe78f8dd7cf6b78c24b96786e8 (diff) | |
download | bugzilla-345e686485e484e087ea58c988e4831209c39554.tar.gz bugzilla-345e686485e484e087ea58c988e4831209c39554.tar.xz |
Bug 1476841 - Various code cleanups ahead of the Mojolicious patch
-rw-r--r-- | Bugzilla.pm | 28 | ||||
-rw-r--r-- | Bugzilla/CPAN.pm | 2 | ||||
-rw-r--r-- | Bugzilla/Constants.pm | 9 | ||||
-rw-r--r-- | Bugzilla/DaemonControl.pm | 19 | ||||
-rw-r--r-- | Bugzilla/Template.pm | 11 | ||||
-rwxr-xr-x | editusers.cgi | 2 | ||||
-rw-r--r-- | mod_perl.pl | 2 | ||||
-rwxr-xr-x | userprefs.cgi | 2 |
8 files changed, 32 insertions, 43 deletions
diff --git a/Bugzilla.pm b/Bugzilla.pm index 29675865b..73d080395 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -13,15 +13,6 @@ use warnings; use Bugzilla::Logging; -# We want any compile errors to get to the browser, if possible. -BEGIN { - # This makes sure we're in a CGI. - if ($ENV{SERVER_SOFTWARE} && !$ENV{MOD_PERL}) { - require CGI::Carp; - CGI::Carp->import('fatalsToBrowser'); - } -} - our $VERSION = '20180717.2'; use Bugzilla::Auth; @@ -202,8 +193,17 @@ sub init_page { # Subroutines and Methods ##################################################################### +my $preload_templates = 0; +sub preload_templates { + $preload_templates = 1; + + delete request_cache->{template}; + template(); + return 1; +} + sub template { - request_cache->{template} ||= Bugzilla::Template->create(); + request_cache->{template} //= Bugzilla::Template->create(preload => $preload_templates); request_cache->{template}->{_is_main} = 1; return request_cache->{template}; @@ -214,7 +214,8 @@ sub template_inner { my $cache = request_cache; my $current_lang = $cache->{template_current_lang}->[0]; $lang ||= $current_lang || ''; - return $cache->{"template_inner_$lang"} ||= Bugzilla::Template->create(language => $lang); + my %options = (language => $lang, preload => $preload_templates); + return $cache->{"template_inner_$lang"} ||= Bugzilla::Template->create(%options); } sub extensions { @@ -234,7 +235,7 @@ sub extensions { } sub cgi { - return request_cache->{cgi} ||= new Bugzilla::CGI(); + return request_cache->{cgi} ||= Bugzilla::CGI->new; } sub input_params { @@ -340,9 +341,6 @@ sub login { return $class->user if $class->user->id; - # Load all extensions here if not running under mod_perl - $class->extensions unless $ENV{MOD_PERL}; - my $authorizer = new Bugzilla::Auth(); $type = LOGIN_REQUIRED if $class->cgi->param('GoAheadAndLogIn'); diff --git a/Bugzilla/CPAN.pm b/Bugzilla/CPAN.pm index d765d2901..1b6fb93b9 100644 --- a/Bugzilla/CPAN.pm +++ b/Bugzilla/CPAN.pm @@ -103,7 +103,7 @@ sub feature { my $meta = $class->cpan_meta; my $feature = $meta->feature($feature_name); my @modules = $feature->prereqs->merged_requirements(['runtime'], ['requires'])->required_modules; - Module::Runtime::require_module($_) foreach @modules; + Module::Runtime::require_module($_) foreach grep { !/^Test::Taint$/ } @modules; return $FEATURE_LOADED{$feature_name} = 1; } diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm index 3aa7b0fa4..185a30390 100644 --- a/Bugzilla/Constants.pm +++ b/Bugzilla/Constants.pm @@ -15,6 +15,7 @@ use base qw(Exporter); # For bz_locations use File::Basename; +use Cwd qw(realpath); use Memoize; @Bugzilla::Constants::EXPORT = qw( @@ -644,12 +645,8 @@ sub _bz_locations { # directory under both mod_cgi and mod_perl. We call dirname twice # to get the name of the directory above the "Bugzilla/" directory. # - # Calling dirname twice like that won't work on VMS or AmigaOS - # but I doubt anybody runs Bugzilla on those. - # - # On mod_cgi this will be a relative path. On mod_perl it will be an - # absolute path. - my $libpath = dirname(dirname($INC{'Bugzilla/Constants.pm'})); + # Always use an absolute path, based on the location of this file. + my $libpath = realpath(dirname(dirname(__FILE__))); # We have to detaint $libpath, but we can't use Bugzilla::Util here. $libpath =~ /(.*)/; $libpath = $1; diff --git a/Bugzilla/DaemonControl.pm b/Bugzilla/DaemonControl.pm index 2c6df1b87..6ff883af0 100644 --- a/Bugzilla/DaemonControl.pm +++ b/Bugzilla/DaemonControl.pm @@ -14,7 +14,7 @@ use Bugzilla::Logging; use Bugzilla::Constants qw(bz_locations); use Cwd qw(realpath); use English qw(-no_match_vars $PROGRAM_NAME); -use File::Spec::Functions qw(catfile); +use File::Spec::Functions qw(catfile catdir); use Future::Utils qw(repeat try_repeat); use Future; use IO::Async::Loop; @@ -40,12 +40,11 @@ our %EXPORT_TAGS = ( utils => [qw(catch_signal on_exception on_finish)], ); -use constant { - JOBQUEUE_BIN => realpath( catfile( bz_locations->{cgi_path}, 'jobqueue.pl' ) ), - CEREAL_BIN => realpath( catfile( bz_locations->{cgi_path}, 'scripts', 'cereal.pl' ) ), - HTTPD_BIN => '/usr/sbin/httpd', - HTTPD_CONFIG => realpath( catfile( bz_locations->{confdir}, 'httpd.conf' ) ), -}; +my $BUGZILLA_DIR = bz_locations->{cgi_path}; +my $JOBQUEUE_BIN = catfile( $BUGZILLA_DIR, 'jobqueue.pl' ); +my $CEREAL_BIN = catfile( $BUGZILLA_DIR, 'scripts', 'cereal.pl' ); +my $HTTPD_BIN = '/usr/sbin/httpd'; +my $HTTPD_CONFIG = catfile( bz_locations->{confdir}, 'httpd.conf' ); sub catch_signal { my ($name, @done) = @_; @@ -76,7 +75,7 @@ sub run_cereal { my $loop = IO::Async::Loop->new; my $exit_f = $loop->new_future; my $cereal = IO::Async::Process->new( - command => [CEREAL_BIN], + command => [$CEREAL_BIN], on_finish => on_finish($exit_f), on_exception => on_exception( 'cereal', $exit_f ), ); @@ -103,7 +102,7 @@ sub run_httpd { # we have to setsid() to make a new process group # or else apache will kill its parent. setsid(); - my @command = ( HTTPD_BIN, '-DFOREGROUND', '-f' => HTTPD_CONFIG, @args ); + my @command = ( $HTTPD_BIN, '-DFOREGROUND', '-f' => $HTTPD_CONFIG, @args ); exec @command or die "failed to exec $command[0] $!"; }, @@ -122,7 +121,7 @@ sub run_jobqueue { my $loop = IO::Async::Loop->new; my $exit_f = $loop->new_future; my $jobqueue = IO::Async::Process->new( - command => [ JOBQUEUE_BIN, 'start', '-f', '-d', @args ], + command => [ $JOBQUEUE_BIN, 'start', '-f', '-d', @args ], on_finish => on_finish($exit_f), on_exception => on_exception( 'httpd', $exit_f ), ); diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 8cf91052e..299734d64 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -565,13 +565,8 @@ sub create { PRE_CHOMP => 1, TRIM => 1, - # Bugzilla::Template::Plugin::Hook uses the absolute (in mod_perl) - # or relative (in mod_cgi) paths of hook files to explicitly compile - # a specific file. Also, these paths may be absolute at any time - # if a packager has modified bz_locations() to contain absolute - # paths. ABSOLUTE => 1, - RELATIVE => $ENV{MOD_PERL} ? 0 : 1, + RELATIVE => 0, # Only use an on-disk template cache if we're running as the web # server. This ensures the permissions of the cache remain correct. @@ -584,7 +579,7 @@ sub create { # Initialize templates (f.e. by loading plugins like Hook). PRE_PROCESS => ["global/initialize.none.tmpl"], - ENCODING => Bugzilla->params->{'utf8'} ? 'UTF-8' : undef, + ENCODING => 'UTF-8', # Functions for processing text within templates in various ways. # IMPORTANT! When adding a filter here that does not override a @@ -1042,7 +1037,7 @@ sub create { # under mod_perl, use a provider (template loader) that preloads all templates into memory my $provider_class - = $ENV{MOD_PERL} + = $opts{preload} ? 'Bugzilla::Template::PreloadProvider' : 'Template::Provider'; diff --git a/editusers.cgi b/editusers.cgi index 9fbd550fe..d2ad3a82f 100755 --- a/editusers.cgi +++ b/editusers.cgi @@ -24,7 +24,7 @@ use Bugzilla::Field; use Bugzilla::Group; use Bugzilla::Token; -my $user = Bugzilla->login(LOGIN_REQUIRED); +local our $user = Bugzilla->login(LOGIN_REQUIRED); my $cgi = Bugzilla->cgi; my $template = Bugzilla->template; diff --git a/mod_perl.pl b/mod_perl.pl index ff84e523e..aeadd6f35 100644 --- a/mod_perl.pl +++ b/mod_perl.pl @@ -104,7 +104,7 @@ Bugzilla::Extension->load_all(); Bugzilla->preload_features(); # Force instantiation of template so Bugzilla::Template::PreloadProvider can do its magic. -Bugzilla->template; +Bugzilla->preload_templates; # Have ModPerl::RegistryLoader pre-compile all CGI scripts. my $rl = new ModPerl::RegistryLoader(); diff --git a/userprefs.cgi b/userprefs.cgi index e70b9780a..830c49eed 100755 --- a/userprefs.cgi +++ b/userprefs.cgi @@ -29,7 +29,7 @@ use DateTime; use constant SESSION_MAX => 20; -my $template = Bugzilla->template; +local our $template = Bugzilla->template; local our $vars = {}; ############################################################################### |