Values lifetime in mod_perl

66 views Asked by At

.pm file:

package fo_condition_editor;

use utf8;
use diagnostics -trace;
use strict;
use warnings FATAL => 'all';

{...}

use Encode;

my $msg = {};

return 1;
{..}
sub ..() {
$msg->{saved} = 1;

I use this pm to show popup. When form is submitted, popup is refreshed.

In my local server everything works fine, but in other server i had problem with variables $msg. $msg is empty during printing, but when i submit again in $msg are old things.

I think is problem with apache configuration.

1

There are 1 answers

2
Georg Mavridis On

The probloem - if I get this correctly - is that the code

my $msg = {};

is only executed when this package is required/used for the first time. After that (in the current mod_perl Instance) this wont be executed any more, and $msg keeps whatever value it has for the next requests.

There are a lot of ways to work around this problem. One schema, I use some times, is to define a "tear-down/reset" method for each "package / module-Entity" I use. In the package itself I push a reference of this method to a global Variable. And in my "core-Handler" called by mod_perl I have a tear-down/reset method, which iterates over the registered handlers and calls them to reset the data.

HTH Georg