催化剂'前进'函数不返回任何值

时间:2017-06-29 11:47:20

标签: perl catalyst

我有这段代码:

my $variable = $c->forward(qw/Curate::Controller::Utils _get_timestamp/);
$c->log->debug("variable is now $variable");

_get_timestamp看起来像这样:

sub _get_timestamp :Private {

    my ( $self, $c, $arg ) = @_;

    my $current_timestamp = "0000-00-00 00:00:00";

    my $coderef = sub {
        my $sth = $c->model('DB')->storage->dbh->prepare('SELECT CURRENT_TIMESTAMP') 
            || die "Couldn't prepare statement: " .  $c->model('DB')->storage->dbh->errstr;

        $sth->execute || die "Couldn't execute statement: " . $sth->errstr;
        $current_timestamp =  $sth->fetchrow_array;
    };

    try {
        $c->model('DB')->schema->txn_do($coderef);
    } catch {
        $c->stash->{error} = "$_";  
    };

    $c->log->debug("returning $current_timestamp");

    return $current_timestamp;

}

当我在日志中运行此代码时,我可以看到:

      returning 2017-06-29 12:34:23
      variable is now 

我不明白为什么变量没有被分配给转发函数返回的值。此代码适用于旧版本的Catalyst。我发布了从CPAN下载的最新版本。您是否了解转发协议的任何变化?

顺便说一句:我知道我可以存储结果,但在这种情况下直接分配似乎更自然。

0 个答案:

没有答案