diff options
author | myk%mozilla.org <> | 2005-02-05 02:04:53 +0100 |
---|---|---|
committer | myk%mozilla.org <> | 2005-02-05 02:04:53 +0100 |
commit | 59d3e617949536d6a89573c11c9680dc5d060019 (patch) | |
tree | 1a0ac5c5026109de6068d79cd721a03e963686c0 | |
parent | d394693b53e364d19c67694b0635f61e34266654 (diff) | |
download | bugzilla-59d3e617949536d6a89573c11c9680dc5d060019.tar.gz bugzilla-59d3e617949536d6a89573c11c9680dc5d060019.tar.xz |
Fix for bug 280770: makes constants from Bugzilla/Constants.pm available to templates via the Template Toolkit's 'constants' namespace (which is like its 'variables' namespace, but for constants); r=wurblzap, a=myk
-rw-r--r-- | Bugzilla/Template.pm | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index cb034478d..a764848be 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -37,6 +37,26 @@ use Date::Format (); use base qw(Template); +# Convert the constants in the Bugzilla::Constants module into a hash we can +# pass to the template object. To do so, we have to traverse the symbol table +# for the module, pulling out the functions (which is how Perl constants are +# implemented) and ignoring the rest (i.e. things like the @EXPORT array). +use Bugzilla::Constants (); +my %constants; +foreach my $constant (keys %Bugzilla::Constants::) { + if (defined &{$Bugzilla::Constants::{$constant}}) { + # Constants can be lists, and we can't know whether we're getting + # a scalar or a list in advance, since they come to us as the return + # value of a function call, so we have to retrieve them all in list + # context into anonymous arrays, then extract the scalar ones (i.e. + # the ones whose arrays contain a single element) from their arrays. + $constants{$constant} = [&{$Bugzilla::Constants::{$constant}}]; + if (scalar(@{$constants{$constant}}) == 1) { + $constants{$constant} = @{$constants{$constant}}[0]; + } + } +} + # XXX - mod_perl my $template_include_path; @@ -361,6 +381,8 @@ sub create { PLUGIN_BASE => 'Bugzilla::Template::Plugin', + CONSTANTS => \%constants, + # Default variables for all templates VARIABLES => { # Function for retrieving global parameters. |