use
Test::More ($] < 5.007001 ? (
skip_all
=>
'open_mode needs at least perl 5.7.1'
) : (
tests
=> 5));
use_ok(
'HTML::Template'
);
my
$cache_dir
= tempdir(
CLEANUP
=> 1);
my
$tmpl
= HTML::Template->new(
path
=>
'templates'
,
filename
=>
'utf8-test.tmpl'
,
open_mode
=>
'<:raw'
,
);
my
$output
=
$tmpl
->output;
is(
sprintf
(
'%vd'
,
$output
),
"195.164.10"
,
'correct raw bytes'
);
$tmpl
= HTML::Template->new(
path
=>
'templates'
,
filename
=>
'utf8-test.tmpl'
,
open_mode
=>
'<:encoding(utf-8)'
,
);
$output
=
$tmpl
->output;
chomp
$output
;
is(
$output
,
chr
(228),
'correct UTF8 encoded character'
);
$tmpl
= HTML::Template->new(
path
=>
'templates'
,
filename
=>
'utf8-test.tmpl'
,
open_mode
=>
'<:encoding(utf-8)'
,
cache
=> 0,
file_cache
=> 1,
file_cache_dir
=>
$cache_dir
,
);
$output
=
$tmpl
->output;
$tmpl
= HTML::Template->new(
path
=>
'templates'
,
filename
=>
'utf8-test.tmpl'
,
open_mode
=>
'<:encoding(utf-8)'
,
cache
=> 0,
file_cache
=> 1,
file_cache_dir
=>
$cache_dir
,
);
$output
=
$tmpl
->output;
chomp
$output
;
is(
$output
,
chr
(228),
'correct UTF8 encoded character from cache'
);
$tmpl
= HTML::Template->new(
path
=>
'templates'
,
filename
=>
'utf8-test.tmpl'
,
cache
=> 0,
file_cache
=> 1,
file_cache_dir
=>
$cache_dir
,
);
$output
=
$tmpl
->output;
chomp
$output
;
is(
sprintf
(
'%vd'
,
$output
),
"195.164"
,
'correct non-UTF8 bytes: different open_mode, no cache'
);