Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl 有没有办法将包/全局变量用于Dancer和Starman?_Perl_Dancer_Starman - Fatal编程技术网

Perl 有没有办法将包/全局变量用于Dancer和Starman?

Perl 有没有办法将包/全局变量用于Dancer和Starman?,perl,dancer,starman,Perl,Dancer,Starman,当运行Starman时,我想不出在Dancer应用程序中使用包变量(或任何类似的东西)的方法。我想这可能与Starman的前期工作有关,但这应该是一个特性,而不是一个bug 以下是示例舞者应用程序: package-nafig; 使用舞蹈演员; 我的$a=0; $b=0; $nafig::c=0; 任何“/”=>sub{ 警告加入“$a++、$b++、$nafig::c++”; }; 开始 然后我连续3次调用该应用程序。首先,我使用plack reference server运行它,一切正常:

当运行Starman时,我想不出在Dancer应用程序中使用包变量(或任何类似的东西)的方法。我想这可能与Starman的前期工作有关,但这应该是一个特性,而不是一个bug

以下是示例舞者应用程序:

package-nafig;
使用舞蹈演员;
我的$a=0;
$b=0;
$nafig::c=0;
任何“/”=>sub{
警告加入“$a++、$b++、$nafig::c++”;
};
开始
然后我连续3次调用该应用程序。首先,我使用plack reference server运行它,一切正常:

$plackup app.pl
HTTP::Server::PSGI:在HTTP://0:5000接受连接/
0在。。。废话废话
1在。。。废话废话
2在。。。废话废话
但当我对Starman做同样的事情时,我得到了以下结果

$plackup-s Starman app.pl
2013/11/17-23:33:35 Starman::Server(键入Net::Server::PreFork)正在启动!pid(527)
已解析[*]:5000到[:]:5000,IPv6
不包括已解析的主机[0.0.0.0]IPv4,因为它将由[:]IPv6处理
使用IPv6绑定到主机::上的TCP端口5000
将gid设置为“1000 1000 20 24 25 29 30 44 46 108 109 115 121 1000”
Starman:在http://*:5000接受连接/
0在。。。废话废话
0在。。。废话废话
0在。。。废话废话
但是,在快速刷新页面时,有时会按预期增加值。我想,在这些情况下,Starman仍然处于同一种状态

我很惊讶这个问题以前从未在stackoverflow上被问过。持久变量对我来说似乎很有用,没有它们人们怎么跳舞


提前感谢您的帮助。

您需要一个类似的模块,它允许您通过分叉线程存储状态

类似这样的东西(未经测试)


从这里改编

使用像mongodb或couchbase这样的轻量级数据库来获取持久值。数据库引擎可以保护您避免同时修改values@user1937198,它不是比将变量存储在内存中要慢得多吗?
use strict;
use warnings;

package nafig; #this should start with a capital letter
use Dancer;
use Cache::Memcached;

my $cache =  new Cache::Memcached {
    'servers' => ['127.0.0.1:11211'],
    'compress_threshold' => 10_000,
};

$cache->set("var1", 0);

any '/' => sub {

    my $value = $cache->get("var1");

    warn join " ", $value++;

    $cache->set("var1", $value);
};

start;