line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Typist::Template::Filters; |
2
|
1
|
|
|
1
|
|
1243
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use vars qw( $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
6
|
|
|
|
|
|
|
$VERSION = 0.11; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Typist::Template::Context; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
80
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use Typist::Util::String |
11
|
1
|
|
|
|
|
970
|
qw( decode_html decode_xml remove_html encode_html encode_xml encode_js |
12
|
1
|
|
|
1
|
|
7
|
encode_php encode_url ); |
|
1
|
|
|
|
|
1
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub import { |
15
|
1
|
|
|
1
|
|
14
|
Typist::Template::Context->add_global_filter('trim_to' => \&trim_to); |
16
|
1
|
|
|
|
|
5
|
Typist::Template::Context->add_global_filter('trim' => \&trim); |
17
|
1
|
|
|
|
|
5
|
Typist::Template::Context->add_global_filter('ltrim' => \<rim); |
18
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter('rtrim' => \&rtrim); |
19
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter( |
20
|
|
|
|
|
|
|
'decode_html' => \&decode_html); |
21
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter('decode_xml' => \&decode_xml); |
22
|
1
|
|
|
|
|
4
|
Typist::Template::Context->add_global_filter( |
23
|
|
|
|
|
|
|
'remove_html' => \&remove_html); |
24
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter( |
25
|
|
|
|
|
|
|
'encode_html' => \&encode_html); |
26
|
1
|
|
|
|
|
4
|
Typist::Template::Context->add_global_filter('encode_xml' => \&encode_xml); |
27
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter('encode_js' => \&encode_js); |
28
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter('encode_php' => \&encode_php); |
29
|
1
|
|
|
|
|
2
|
Typist::Template::Context->add_global_filter('encode_url' => \&encode_url); |
30
|
1
|
|
|
|
|
4
|
Typist::Template::Context->add_global_filter('upper_case' => \&uppper_case); |
31
|
1
|
|
|
|
|
34
|
Typist::Template::Context->add_global_filter('lower_case' => \&lower_case); |
32
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter( |
33
|
|
|
|
|
|
|
'strip_linefeeds' => \&strip_linefeeds); |
34
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter('space_pad' => \&space_pad); |
35
|
1
|
|
|
|
|
4
|
Typist::Template::Context->add_global_filter('zero_pad' => \&zero_pad); |
36
|
1
|
|
|
|
|
3
|
Typist::Template::Context->add_global_filter('sprintf' => \&sprintf); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
0
|
1
|
|
sub trim_to { $_[1] < length($_[0]) ? substr $_[0], 0, $_[1] : $_[0] } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub trim { |
42
|
0
|
|
|
0
|
1
|
|
my $str = shift; |
43
|
0
|
|
|
|
|
|
$str =~ s/(^\s+|\s+$)//sg; |
44
|
0
|
|
|
|
|
|
$str; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ltrim { |
48
|
0
|
|
|
0
|
1
|
|
my $str = shift; |
49
|
0
|
|
|
|
|
|
$str =~ s/^\s+//s; |
50
|
0
|
|
|
|
|
|
$str; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub rtrim { |
54
|
0
|
|
|
0
|
1
|
|
my $str = shift; |
55
|
0
|
|
|
|
|
|
$str =~ s/\s+$//s; |
56
|
0
|
|
|
|
|
|
$str; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
0
|
1
|
|
sub upper_case { uc($_[0]) } |
60
|
0
|
|
|
0
|
1
|
|
sub lower_case { lc($_[0]) } |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub strip_linefeeds { |
63
|
0
|
|
|
0
|
1
|
|
my $str = shift; |
64
|
0
|
|
|
|
|
|
$str =~ tr{\r\n}{}d; |
65
|
0
|
|
|
|
|
|
$str; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub space_pad { |
69
|
0
|
|
|
0
|
1
|
|
my ($str, $len) = @_; |
70
|
0
|
|
|
|
|
|
$str = sprintf "%${len}s", $str; |
71
|
0
|
|
|
|
|
|
$str; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub zero_pad { |
75
|
0
|
|
|
0
|
1
|
|
my ($str, $len) = @_; |
76
|
0
|
|
|
|
|
|
$str = sprintf "%0${len}s", $str; |
77
|
0
|
|
|
|
|
|
$str; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub sprintf { |
81
|
0
|
|
|
0
|
1
|
|
my ($str, $format) = @_; |
82
|
0
|
|
|
|
|
|
$str = sprintf($format, $str); |
83
|
0
|
|
|
|
|
|
$str; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |