How to understand subcall "sub ($c) {...}"?

244 Views Asked by At

I'm reading a mojo example from: https://mojolicious.org/ Below is the code:

use Mojolicious::Lite -signatures;

# Render template "index.html.ep" from the DATA section
get '/' => sub ($c) {
  $c->render(template => 'index');
};

......

My question is how to get this piece of code compiled by perl? Usually I'll code subcalls as:

get '/' => sub {
      my $c = shift;
      $c->render(template => 'index');
    };

This could be compiled well by strawberry perl. While the example code from mojo got errors:

D:\Source\test_code\mojotest>perl mojo3.pl daemon
Illegal character in prototype for ? : $c at mojo3.pl line 4.
Illegal character in prototype for ? : $c at mojo3.pl line 9.
Illegal character in prototype for ? : $c, $msg at mojo3.pl line 10.

Could anyone tell why?

0

There are 0 best solutions below