Difference between %= and %== on undefined data

30 views
Skip to first unread message

Lars Madsen

unread,
Sep 9, 2019, 7:27:28 AM9/9/19
to Mojolicious
During my build of my first poper fully functional Mojo app, I came acros the following and I don't really know if this is intentional (or if it has been addressed already)

Below is a lite app that shows the problem, in my case I'm getting some data from a database adding them to a form (given to taghelpers) and also add the data to a live preview part where the data is just inserted via %= param('field') or %== param('field'). Some data may be null fields. and that gave raise to this small difference.

So my question is: Is %= and %== suppose to have different handling of undef data?


#!/usr/bin/env perl
use Mojolicious::Lite;

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

app->start;
__DATA__

@@ index.html.ep
% layout 'default';
% title 'Welcome';

This is testing a bug in Mojo::Template: The term <code>%= param('bug')</code>  handles undefined 'bug' just fine,
whereas <code>%== param('bug')</code>  gives an <code style="color:red">Use of uninitialized value in concatenation</code> warning in morbo


%= param('bug')
%== param('bug')

%= undef
%== undef



@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
  <head><title><%= title %></title></head>
  <body><%= content %></body>
</html>

/daleif

Justin Hawkins

unread,
Sep 11, 2019, 7:17:28 AM9/11/19
to mojol...@googlegroups.com


On 9 Sep 2019, at 8:43 pm, Lars Madsen <dal...@gmail.com> wrote:

So my question is: Is %= and %== suppose to have different handling of undef data?


Hi Lars,

Not specifically different, but %= will escape the data and %== passes it straight through. Presumably the escaping has handling for undef data which prevents “use of uninitialised” warnings. 

In general, making sure "uninitialised value" warnings don’t get emitted is your problem, not the frameworks. An undef being printed or otherwise emitted to the end user is generally a code smell.

Cheers,

Justin
Reply all
Reply to author
Forward
0 new messages