I'm using Mojolicious (not Lite) together with CPAN::Redis.
I'm storing some data which is Japanese encoded in this way:
use Redis;
my $redis = Redis->new;
$redis->set("mykey",$val);
# $val contains a string which was read from a file.
# The value looks like: テスト
Later in the code I read that value from redis:
my $val = $redis->get("mykey");
print Dumper($val); #the value prints correctly in terminal
$self->stash(
myvalue => $val
);
$self->render(
template => "/pages/test"
);
And the template:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div><%= $myvalue %></div>
...
But it display the value like: ãã¹ã.
Changing the charset manually in the browser makes no difference (it is not displayed as expected).
Why if its displayed correctly in the terminal, it is not displayed correctly in the template?
I hate to answer my own questions.. but I found the solution:
use Encode qw(decode_utf8);
...
$self->stash(
myvalue => decode_utf8($val)
);
Simple as that. Not sure why its displayed correctly on the terminal... Probably "Dumper" is converting it?