Mojolicious and special variable names
I recently started using Mojolicious and this week I encountered a problem when stashing data for rendering in the template.
I tried to stash a reference like this:
my $data = from_json($json_string);
$self->stash(data => $data);
Now when reloading the page it will just render something like HASH(0x85af7b0).
What has happened here is that the "data" variable is used by Mojolicious internally and that is what is rendered instead of the template.
If someone can write a better explanation or point to where this is documented please do so.
I've found this to be an annoying issue in my (admittedly limited) experience of Mojolicious. It's a fantastic platform but it makes little effort to protect the namespaces it uses for all sorts of things. I've ended up using a common prefix for everything to keep things consistent and (hopefully) avoid this issue.
There's been a relatively recent change to helpers that allows you to create a sort of private namespace for them, though the name of that namespace is itself in an unprotected namespace :), so I guess this problem is not off the radar of the dev team. I have been trying to make time to investigate further and perhaps even offer something constructive. It might happen one day...
check --> https://metacpan.org/pod/Mojolicious::Controller#stash
"the full list is currently action, app, cb, controller, data, extends, format, handler, json, layout, namespace, path, status, template, text and variant."