File Coverage

blib/lib/Sledge/Template/TT/I18N.pm
Criterion Covered Total %
statement 15 32 46.8
branch 0 8 0.0
condition n/a
subroutine 5 8 62.5
pod 0 1 0.0
total 20 49 40.8


line stmt bran cond sub pod time code
1             package Sledge::Template::TT::I18N;
2 1     1   48693 use strict;
  1         3  
  1         57  
3 1     1   19 use base qw(Sledge::Template::TT);
  1         3  
  1         1184  
4              
5 1     1   9 use vars qw($VERSION);
  1         16  
  1         719  
6             $VERSION = '0.01';
7              
8             sub output {
9 0     0 0   my $self = shift;
10 0           my %config = %{$self->{_options}};
  0            
11 0           my $input = delete $config{filename};
12 0           $config{LOAD_TEMPLATES} = [Sledge::Template::TT::I18N::Provider->new(\%config)];
13 0           my $template = Template->new(\%config);
14 0 0         unless (-e $input) {
15 0           Sledge::Exception::TemplateNotFound->throw(
16             "No template file detected. Check your template path.",
17             );
18             }
19 0 0         $template->process($input, $self->{_params}, \my $output)
20             or Sledge::Exception::TemplateParseError->throw($template->error);
21 0           return $output;
22             }
23              
24             package Sledge::Template::TT::I18N::Provider;
25 1     1   8 use strict;
  1         2  
  1         44  
26 1     1   5 use base qw(Template::Provider);
  1         2  
  1         5160  
27              
28             sub _load {
29 0     0     my $self = shift;
30              
31 0           my ($data, $error) = $self->SUPER::_load(@_);
32              
33 0 0         if(defined $data) {
34 0           $data->{text} = utf8_upgrade($data->{text});
35             }
36              
37 0           return ($data, $error);
38             }
39              
40             sub utf8_upgrade {
41 0     0     my @list = map pack('U*', unpack 'U0U*', $_), @_;
42 0 0         return wantarray ? @list : $list[0];
43             }
44              
45             1;
46             __END__