简体   繁体   English

值mod_perl中的生命周期

[英]Values lifetime in mod_perl

.pm file: .pm文件:

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的问题。 $msg is empty during printing, but when i submit again in $msg are old things. $ msg在打印过程中是空的,但是当我再次提交$ msg时是旧东西。

I think is problem with apache configuration. 我认为apache配置有问题。

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. 之后(在当前的mod_perl实例中)将不再执行此操作,并且$ msg保留其对下一个请求的任何值。

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. 在由mod_perl调用的“核心处理程序”中,我有一个拆卸/重置方法,该方法遍历已注册的处理程序并调用它们以重置数据。

HTH Georg HTH乔治

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM