From 14bcdce1dc6029c3676c3640d8148c83c14692e5 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Mon, 12 Sep 2016 16:22:17 -0400 Subject: Revert "Bug 1283930 - Add Makefile.PL & local/lib/perl5 support to bmo/master + local symlink to data/ directory" This reverts commit e6bf4cacb10f86077fe898349485f5c7ab9fb4b6. --- Bugzilla.pm | 90 ++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 37 deletions(-) (limited to 'Bugzilla.pm') diff --git a/Bugzilla.pm b/Bugzilla.pm index 72192d41a..56bbb5c15 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -1,15 +1,30 @@ -# 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/. +# -*- Mode: perl; indent-tabs-mode: nil -*- # -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the Bugzilla Bug Tracking System. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): Bradley Baetz +# Erik Stambaugh +# A. Karl Kornel +# Marc Schumann package Bugzilla; -use 5.10.1; use strict; -use warnings; # We want any compile errors to get to the browser, if possible. BEGIN { @@ -32,8 +47,8 @@ use Bugzilla::Field; use Bugzilla::Flag; use Bugzilla::Hook; use Bugzilla::Install::Localconfig qw(read_localconfig); +use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES); use Bugzilla::Install::Util qw(init_console include_languages); -use Bugzilla::Install::Requirements qw(load_cpan_meta check_cpan_feature); use Bugzilla::Memcached; use Bugzilla::Template; use Bugzilla::Token; @@ -238,7 +253,7 @@ sub extensions { my $extension = $package->new(); if ($extension->enabled) { push(@extensions, $extension); - } + } } $cache->{extensions} = \@extensions; } @@ -246,36 +261,37 @@ sub extensions { } sub feature { - my ($class, $feature_name) = @_; - return 0 unless CAN_HAS_FEATURE; - return 0 unless $class->has_feature($feature_name); - - my $cache = $class->process_cache; - my $feature = $cache->{cpan_meta}->feature($feature_name); - # Bugzilla expects this will also load all the modules.. so we have to do that. - # Later we should put a deprecation warning here, and favor calling has_feature(). - - return 1 if $cache->{feature_loaded}{$feature_name}; - my @modules = $feature->prereqs->merged_requirements->required_modules; - Module::Runtime::require_module($_) foreach @modules; - $cache->{feature_loaded}{$feature_name} = 1; - return 1; -} - -sub has_feature { - my ($class, $feature_name) = @_; - - return 0 unless CAN_HAS_FEATURE; - - my $cache = $class->process_cache; - return $cache->{feature}->{$feature_name} - if exists $cache->{feature}->{$feature_name}; + my ($class, $feature) = @_; + my $cache = $class->request_cache; + return $cache->{feature}->{$feature} + if exists $cache->{feature}->{$feature}; + + my $feature_map = $cache->{feature_map}; + if (!$feature_map) { + foreach my $package (@{ OPTIONAL_MODULES() }) { + foreach my $f (@{ $package->{feature} }) { + $feature_map->{$f} ||= []; + push(@{ $feature_map->{$f} }, $package->{module}); + } + } + $cache->{feature_map} = $feature_map; + } - my $meta = $cache->{cpan_meta} //= load_cpan_meta(); - my $feature = eval { $meta->feature($feature_name) } - or ThrowCodeError('invalid_feature', { feature => $feature_name }); + if (!$feature_map->{$feature}) { + ThrowCodeError('invalid_feature', { feature => $feature }); + } - return $cache->{feature}{$feature_name} = check_cpan_feature($feature)->{ok}; + my $success = 1; + foreach my $module (@{ $feature_map->{$feature} }) { + # We can't use a string eval and "use" here (it kills Template-Toolkit, + # see https://rt.cpan.org/Public/Bug/Display.html?id=47929), so we have + # to do a block eval. + $module =~ s{::}{/}g; + $module .= ".pm"; + eval { require $module; 1; } or $success = 0; + } + $cache->{feature}->{$feature} = $success; + return $success; } sub cgi { -- cgit v1.2.3-24-g4f1b