Search code examples
perlmason

Defining global variables in perl Mason Framework


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.


Solution

  • 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