Defining global variables in perl Mason Framework

1.1k Views Asked by At

I recently came across a problem: how to define a global variable in perl Mason Framework ? I need to define a variable and assign a value to it which will be visible from all Mason components, but all my attempts happen to be unsuccessful, because components tell that they don't see the variable.

Thanks in advance.

1

There are 1 best solutions below

4
On BEST ANSWER

You will need to declare the global variables in the allow_globals parameter in your Apache config or when you build your Mason interpreter object.

Example when using a Mason interpreter object:

my $interp = HTML::Mason::Interp->new(
    ...,
    allow_globals => [
        '$global',
    ],
);

Example with Apache config:

PerlAddVar MasonAllowGlobals $global