File Coverage

blib/lib/Template/Plugin/Filter/VisualTruncate/UTF8.pm
Criterion Covered Total %
statement 26 27 96.3
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 1 3 33.3
total 37 41 90.2


line stmt bran cond sub pod time code
1             package Template::Plugin::Filter::VisualTruncate::UTF8;
2              
3 2     2   1813 use warnings;
  2         5  
  2         74  
4 2     2   13 use strict;
  2         3  
  2         76  
5              
6 2     2   13 use base qw( Template::Plugin::Filter );
  2         5  
  2         16  
7              
8 2     2   7030 use Text::VisualWidth::UTF8;
  2         12947  
  2         25  
9              
10             sub new {
11 2     2 1 5 my $class = shift;
12              
13 2         7 my $self = {};
14 2         9 bless $self, $class;
15              
16 2         10 return $self;
17             }
18              
19             sub width {
20 48     48 0 66 shift;
21 48         163 Text::VisualWidth::UTF8::width(@_);
22             }
23              
24             sub trim {
25 24     24 0 6625 shift;
26 24         72 my $before_flag = utf8::is_utf8($_[0]);
27 24         104 my $truncated = Text::VisualWidth::UTF8::trim(@_);
28 24         682 my $after_flag = utf8::is_utf8($truncated);
29              
30 24 100       91 unless ($before_flag == $after_flag) {
31 10 50       47 if ($before_flag) {
32 10         32 utf8::decode($truncated);
33             }
34             else {
35 0         0 utf8::encode($truncated);
36             }
37             }
38              
39 24         108 $truncated;
40             }
41              
42             1;