line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Dapper::Filters; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
App::Dapper::Filters - Default Liquid filters available to all projects. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Filters contained here can be called from Liquid template files using |
10
|
|
|
|
|
|
|
the filter/pipe mechanism built in to Liquid. Example: |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
{{ site.time | date_to_xmlschema }} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
11
|
use utf8; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
17
|
2
|
|
|
2
|
|
60
|
use open ':std', ':encoding(UTF-8)'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
9
|
|
18
|
2
|
|
|
2
|
|
969
|
use 5.8.0; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
70
|
|
19
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
20
|
2
|
|
|
2
|
|
9
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
82
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
11
|
use Data::Dumper; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
121
|
|
23
|
2
|
|
|
2
|
|
4240
|
use CGI qw(:standard escapeHTML); |
|
2
|
|
|
|
|
31536
|
|
|
2
|
|
|
|
|
15
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 import |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Called when this module is 'used' from somewhere else. This subroutine |
28
|
|
|
|
|
|
|
registers Liquid filters contained in this file. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#sub import { |
33
|
|
|
|
|
|
|
# $filters = Template::Filters->new({ |
34
|
|
|
|
|
|
|
# FILTERS => { |
35
|
|
|
|
|
|
|
# 'xml_escape' => \&xml_escape, |
36
|
|
|
|
|
|
|
# 'date_to_xmlschema' => \&date_to_xmlschema, |
37
|
|
|
|
|
|
|
# 'replace_last' => \&replace_last, |
38
|
|
|
|
|
|
|
# 'smart' => \&smart, |
39
|
|
|
|
|
|
|
# 'json' => \&json, |
40
|
|
|
|
|
|
|
# }, |
41
|
|
|
|
|
|
|
# }); |
42
|
|
|
|
|
|
|
#} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 xml_escape |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Liquid filter to escape strings into formats that can be included |
47
|
|
|
|
|
|
|
in XML files. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=cut |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub xml_escape { |
52
|
0
|
|
|
0
|
1
|
|
my $str = shift; |
53
|
0
|
|
|
|
|
|
my $q = new CGI; |
54
|
0
|
|
|
|
|
|
return $q->escapeHTML( $str ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 date_to_xmlschema |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Convert a date to an XML-formattted version of the date that also includes |
60
|
|
|
|
|
|
|
the timezone. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub date_to_xmlschema { |
65
|
0
|
|
|
0
|
1
|
|
my $str = shift; |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
2
|
|
8021
|
use DateTime; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
68
|
2
|
|
|
2
|
|
2032
|
use DateTime::Format::XSD; |
|
2
|
|
|
|
|
99234
|
|
|
2
|
|
|
|
|
467
|
|
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return DateTime::Format::XSD->format_datetime($str); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 replace_last |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Liquid filter to replace the last occurrance of a string with another string. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub replace_last { |
80
|
0
|
|
|
0
|
1
|
|
my ($input, $string, $replacement) = @_; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
$replacement = defined $replacement ? $replacement : ''; |
83
|
0
|
|
|
|
|
|
$input =~ s/^(.*)$string(.*)$/$1$replacement$2/s; |
84
|
0
|
|
|
|
|
|
return $input; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 smart |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Replace dashes with mdashes and ndashes. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub smart { |
94
|
0
|
|
|
0
|
1
|
|
my $input = shift; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$input =~ s/([^-])--([^-])/$1\–$2/g; |
97
|
0
|
|
|
|
|
|
$input =~ s/([^-])---([^-])/$1\—$2/g; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $input; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 json |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Turn string into json-formatted string. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
2
|
|
2562
|
use JSON; |
|
2
|
|
|
|
|
46489
|
|
|
2
|
|
|
|
|
15
|
|
109
|
|
|
|
|
|
|
sub json { |
110
|
0
|
|
|
0
|
1
|
|
my $input = shift; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $flags = { |
113
|
|
|
|
|
|
|
allow_blessed => 1, |
114
|
|
|
|
|
|
|
allow_barekey => 1, |
115
|
|
|
|
|
|
|
allow_nonref => 1, |
116
|
|
|
|
|
|
|
utf8 => 1, |
117
|
|
|
|
|
|
|
pretty => 1 |
118
|
|
|
|
|
|
|
}; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
return to_json($input, $flags); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |