line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Plugin::Filter::VisualTruncate::Locale; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1258
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base qw( Template::Plugin::Filter ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
965
|
use locale; |
|
1
|
|
|
|
|
244
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
#use POSIX qw(locale_h); |
10
|
|
|
|
|
|
|
#setlocale(LC_CTYPE, "ja_JP.eucJP"); |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
900
|
use Text::CharWidth qw(mbwidth mbswidth mblen); |
|
1
|
|
|
|
|
722
|
|
|
1
|
|
|
|
|
262
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
2
|
|
|
2
|
1
|
3232
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
|
|
4
|
my $self = {}; |
18
|
2
|
|
|
|
|
6
|
bless $self, $class; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
12
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub width { |
24
|
1
|
|
|
1
|
0
|
3
|
shift; |
25
|
1
|
|
|
|
|
38
|
mbswidth(@_); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub trim { |
29
|
0
|
|
|
0
|
0
|
|
my ($self, $text, $len) = @_; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $cur = 0; |
32
|
0
|
|
|
|
|
|
my $trim = ""; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
return $text if mbswidth($text) <= $len; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
0
|
|
|
|
while (length($text) and $len >= (mbwidth($text) + $cur)) { |
37
|
0
|
|
|
|
|
|
$cur += mbwidth($text); |
38
|
0
|
|
|
|
|
|
$trim .= substr($text, 0, mblen($text)); |
39
|
0
|
|
|
|
|
|
$text = substr($text, mblen($text)); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $trim; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |