2

I have this code:

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

And the _get_timestamp looks like this:

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;

}

When I run this code in the logs I can see:

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

I don't understand why the variable did not get assigned to the value returned by the forwarded function. This code works correctly with the old version of Catalyst. I am having this issued with the latest one downloaded from CPAN. Are you aware about any changes in forwarding protocol?

BTW: I know I can stash the result but a direct assignment seems more natural in this case.

8
  • What about $c->error?
    – choroba
    Commented Jun 29, 2017 at 12:09
  • Nothing, there is no error as you see the last but one line of the function code prints the correct value.
    – mnowotka
    Commented Jun 29, 2017 at 12:10
  • 1
    Where's the semicolon after the 1st line?
    – choroba
    Commented Jun 29, 2017 at 12:18
  • Sorry just a typo here, not in the code. It's corrected now.
    – mnowotka
    Commented Jun 29, 2017 at 12:34
  • 2
    "I can give an example of other function, that does not connect to DB" ... then do that. While you are at it, put together something we can run which still exhibits the problem. Commented Jun 29, 2017 at 12:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.