Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Template / Stash / ForceUTF8.pm
1 package Template::Stash::ForceUTF8;
2
3 use strict;
4 our $VERSION = '0.03';
5
6 use Template::Config;
7 use base ( $Template::Config::STASH );
8 use Encode;
9
10 sub get {
11     my $self = shift;
12     my $result = $self->SUPER::get(@_);
13     return $result if ref $result;
14
15     Encode::_utf8_on($result) unless Encode::is_utf8($result);
16     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