From 58787923c838e5a1fc90d3f98e27a443bb1e1122 Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Wed, 30 Sep 2009 22:39:28 +0000 Subject: Bug 509053: Implement Bugzilla->feature (feature_enabled in the templates), and use it to detect when PatchReader is available. Patch by Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'Bugzilla.pm') diff --git a/Bugzilla.pm b/Bugzilla.pm index 671cda38d..43a9b39ae 100644 --- a/Bugzilla.pm +++ b/Bugzilla.pm @@ -42,6 +42,7 @@ use Bugzilla::Auth::Persist::Cookie; use Bugzilla::CGI; use Bugzilla::DB; use Bugzilla::Install::Localconfig qw(read_localconfig); +use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES); use Bugzilla::JobQueue; use Bugzilla::Template; use Bugzilla::User; @@ -187,6 +188,40 @@ sub template_inner { return $class->request_cache->{"template_inner_$lang"}; } +sub feature { + 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; + } + + if (!$feature_map->{$feature}) { + ThrowCodeError('invalid_feature', { feature => $feature }); + } + + 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 { my $class = shift; $class->request_cache->{cgi} ||= new Bugzilla::CGI(); @@ -759,4 +794,9 @@ Returns a L that you can use for queueing jobs. Will throw an error if job queueing is not correctly configured on this Bugzilla installation. +=item C + +Tells you whether or not a specific feature is enabled. For names +of features, see C in C. + =back -- cgit v1.2.3-24-g4f1b