Commit 2e7ff851 authored by myk%mozilla.org's avatar myk%mozilla.org

Followup fix for bug 280770: improves reflection of constants into the…

Followup fix for bug 280770: improves reflection of constants into the templates' 'constants' namespace; r=wurblzap, a=myk
parent f6d43957
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
# Bradley Baetz <bbaetz@student.usyd.edu.au> # Bradley Baetz <bbaetz@student.usyd.edu.au>
# Christopher Aillon <christopher@aillon.com> # Christopher Aillon <christopher@aillon.com>
# Tobias Burnus <burnus@net-b.de> # Tobias Burnus <burnus@net-b.de>
# Myk Melez <myk@mozilla.org>
package Bugzilla::Template; package Bugzilla::Template;
...@@ -38,12 +39,16 @@ use Date::Format (); ...@@ -38,12 +39,16 @@ use Date::Format ();
use base qw(Template); use base qw(Template);
# Convert the constants in the Bugzilla::Constants module into a hash we can # 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 # pass to the template object for reflection into its "constants" namespace
# for the module, pulling out the functions (which is how Perl constants are # (which is like its "variables" namespace, but for constants). To do so, we
# implemented) and ignoring the rest (i.e. things like the @EXPORT array). # traverse the arrays of exported and exportable symbols, pulling out functions
# (which is how Perl implements constants) and ignoring the rest (which, if
# Constants.pm exports only constants, as it should, will be nothing else).
use Bugzilla::Constants (); use Bugzilla::Constants ();
my %constants; my %constants;
foreach my $constant (keys %Bugzilla::Constants::) { foreach my $constant (@Bugzilla::Constants::EXPORT,
@Bugzilla::Constants::EXPORT_OK)
{
if (defined &{$Bugzilla::Constants::{$constant}}) { if (defined &{$Bugzilla::Constants::{$constant}}) {
# Constants can be lists, and we can't know whether we're getting # 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 # a scalar or a list in advance, since they come to us as the return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment