diff options
author | 2009-09-30 22:39:28 +0000 | |
---|---|---|
committer | 2009-09-30 22:39:28 +0000 | |
commit | 58787923c838e5a1fc90d3f98e27a443bb1e1122 (patch) | |
tree | 52c55649b3d9283985a5612393ad1a9276435f94 /Bugzilla.pm | |
parent | Bug 512623: Change get_status and get_resolution to display_value everywhere. (diff) | |
download | bugzilla-58787923c838e5a1fc90d3f98e27a443bb1e1122.tar.gz bugzilla-58787923c838e5a1fc90d3f98e27a443bb1e1122.tar.bz2 bugzilla-58787923c838e5a1fc90d3f98e27a443bb1e1122.zip |
Bug 509053: Implement Bugzilla->feature (feature_enabled in the templates), and use it to detect when PatchReader is available.
Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=LpSolit
Diffstat (limited to 'Bugzilla.pm')
-rw-r--r-- | Bugzilla.pm | 40 |
1 files changed, 40 insertions, 0 deletions
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<Bugzilla::JobQueue> that you can use for queueing jobs. Will throw an error if job queueing is not correctly configured on this Bugzilla installation. +=item C<feature> + +Tells you whether or not a specific feature is enabled. For names +of features, see C<OPTIONAL_MODULES> in C<Bugzilla::Install::Requirements>. + =back |