line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Like::Filters; |
2
|
|
|
|
|
|
|
|
3
|
13
|
|
|
13
|
|
73
|
use strict; |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
11373
|
|
4
|
|
|
|
|
|
|
|
5
|
103
|
|
|
103
|
0
|
412
|
sub new { bless {}, $_[0]; } |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub format { |
8
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $text, $format ) = @_; |
9
|
|
|
|
|
|
|
|
10
|
1
|
50
|
|
|
|
6
|
if ( $text=~/\x0D|\x0A/ ) { |
11
|
0
|
|
|
|
|
0
|
$text=~s/((?:(?!\x0D|\x0A).)+)/sprintf($format, $1)/eg; |
|
0
|
|
|
|
|
0
|
|
12
|
0
|
|
|
|
|
0
|
return $text; |
13
|
|
|
|
|
|
|
} else { |
14
|
1
|
|
|
|
|
7
|
return sprintf $format, $text; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub html { |
19
|
5
|
|
|
5
|
0
|
258
|
my ( $self, $text ) = @_; |
20
|
5
|
50
|
|
|
|
16
|
return undef unless defined $text; |
21
|
5
|
|
|
|
|
15
|
$text =~ s{&}{&}gso; |
22
|
5
|
|
|
|
|
16
|
$text =~ s{<}{<}gso; |
23
|
5
|
|
|
|
|
430
|
$text =~ s{>}{>}gso; |
24
|
5
|
|
|
|
|
13
|
$text =~ s{"}{"}gso; |
25
|
5
|
|
|
|
|
190
|
return $text; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub html_line_break { |
29
|
5
|
|
|
5
|
0
|
12
|
my ( $self, $text ) = @_; |
30
|
5
|
50
|
|
|
|
21
|
return undef unless defined $text; |
31
|
5
|
|
|
|
|
75
|
$text =~s/(\x0D\x0A|\x0A)/ $1/g; |
32
|
5
|
|
|
|
|
69
|
return $text; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub uri { |
36
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $text ) = @_; |
37
|
1
|
|
|
|
|
6
|
$text =~ s/(\W)/'%' . unpack('H2', $1)/eg; |
|
13
|
|
|
|
|
47
|
|
38
|
1
|
|
|
|
|
12
|
return $text; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub truncate { |
42
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $text, $length ) = @_; |
43
|
1
|
50
|
|
|
|
4
|
return undef if $length=~/\D/; |
44
|
1
|
50
|
|
|
|
6
|
return $text if length($text) <= $length; |
45
|
1
|
50
|
|
|
|
3
|
return substr($text, 0, $length) if $length < 4; |
46
|
1
|
|
|
|
|
14
|
return substr($text, 0, ($length - 3)) . '...'; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub repeat { |
50
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $text, $iterations ) = @_; |
51
|
1
|
50
|
33
|
|
|
9
|
return undef if $iterations=~/\D/ || $iterations < 1; |
52
|
1
|
|
|
|
|
12
|
return $text x $iterations; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub remove { |
56
|
1
|
|
|
1
|
0
|
3
|
my ( $self, $text, $string ) = @_; |
57
|
1
|
|
|
|
|
15
|
$text=~s/$string//g; |
58
|
1
|
|
|
|
|
31
|
return $text; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub replace { |
62
|
1
|
|
|
1
|
0
|
4
|
my ( $self, $text, $search, $replace ) = @_; |
63
|
1
|
|
|
|
|
12
|
$text=~s/$search/$replace/g; |
64
|
1
|
|
|
|
|
12
|
return $text; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub comma { |
68
|
0
|
|
|
0
|
0
|
|
my ( $self, $num, $len ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
0
|
|
|
|
$len ||= 3; |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my ( $i, $j ); |
73
|
0
|
0
|
|
|
|
|
if ($num =~ /^[-+]?\d\d\d\d+/g) { |
74
|
0
|
|
|
|
|
|
for ($i = pos($num) - $len, $j = $num =~ /^[-+]/; $i > $j; $i -= $len) { |
75
|
0
|
|
|
|
|
|
substr($num, $i, 0) = ','; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return $num; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |