mojo
mojo copied to clipboard
Warning: Use of "scalar" without parentheses is ambiguous at...
- Mojolicious version: 9.20
- Perl version: 5.28.2
- Operating system: Ubuntu 20.04.2 LTS The warning is seen on other versions of Perl too. Here are some unrelated test failures of one of my modules, but I present them here, because we have a log showing the warning. https://www.cpantesters.org/cpan/report/8028540c-cb98-11eb-bf00-5e721f24ea8f https://www.cpantesters.org/cpan/report/b151802a-cb94-11eb-a6d9-9af5c36c90a2 https://www.cpantesters.org/cpan/report/861922a6-cb98-11eb-bf00-5e721f24ea8f
Steps to reproduce the behaviour
I like signatures and want to use them even in templates for some closures. For example:
% my $images = $processed->map(sub($img) { $cat->[0] eq $img->[0] ? $img : (); });
Prepare a template in which signatures feature is imported.
$ mojo eval 'say Mojo::Template->new(vars => 1)->render("<%use Mojo::Base -signatures;%><%= \$foo %>", {foo => "bar"});'
Warning: Use of "scalar" without parentheses is ambiguous at template line 1.
bar
Expected behaviour
$ mojo eval 'say Mojo::Template->new(vars => 1)->render("<%use Mojo::Base -signatures;%><%= \$foo %>", {foo => "bar"});'
bar
Actual behaviour
We see warnings for each <%= $some_variable %>
. We should not see such warnings.
Solution
Use parentheses with scalar()
This warning comes from Mojo::Template from the following lines of code:
# Escaped
if (!$multi && ($op eq 'escp' && !$escape || $op eq 'expr' && $escape)) {
$blocks[-1] .= "\$_O .= _escape scalar( + $value)";
}
# Raw
elsif (!$multi) { $blocks[-1] .= "\$_O .= scalar( + $value)" }