line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Stash::ForceUTF8; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
65578
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
113
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
13
|
use Template::Config; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
7
|
2
|
|
|
2
|
|
10
|
use base ( $Template::Config::STASH ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2048
|
|
8
|
2
|
|
|
2
|
|
48691
|
use Encode; |
|
2
|
|
|
|
|
12044
|
|
|
2
|
|
|
|
|
346
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub get { |
11
|
15
|
|
|
15
|
1
|
17083
|
my $self = shift; |
12
|
15
|
|
|
|
|
176
|
my $result = $self->SUPER::get(@_); |
13
|
15
|
50
|
|
|
|
79
|
return $result if ref $result; |
14
|
|
|
|
|
|
|
|
15
|
15
|
100
|
|
|
|
62
|
Encode::_utf8_on($result) unless Encode::is_utf8($result); |
16
|
15
|
|
|
|
|
47
|
return $result; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
1; |
20
|
|
|
|
|
|
|
__END__ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Template::Stash::ForceUTF8 - Force UTF-8 (Unicode) flag on stash variables |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
use Template::Stash::ForceUTF8; |
29
|
|
|
|
|
|
|
use Template; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $tt = Template->new( |
32
|
|
|
|
|
|
|
LOAD_TEMPLATES => [ Template::Provider::Encoding->new ], |
33
|
|
|
|
|
|
|
STASH => Template::Stash::ForceUTF8->new, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $vars; |
37
|
|
|
|
|
|
|
$vars->{foo} = "\x{5bae}\x{5ddd}"; # Unicode flagged |
38
|
|
|
|
|
|
|
$vars->{bar} = "\xe5\xae\xae\xe5\xb7\x9d"; # UTF-8 bytes |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$tt->process($template, $vars); # this DWIMs |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Template::Stash::ForceUTF8 is a Template::Stash that forces Unicode |
45
|
|
|
|
|
|
|
flag on stash variables. Best used with L<Template::Provider::Encoding>. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 SEE ALSO |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
L<Template::Provider::Encoding> |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |