line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::FormValidator::Filters::WikiTrim; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################################################################### |
4
|
|
|
|
|
|
|
# Required inclusions. |
5
|
|
|
|
|
|
|
############################################################################### |
6
|
1
|
|
|
1
|
|
148517
|
use strict; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
############################################################################### |
10
|
|
|
|
|
|
|
# Export a few of our methods |
11
|
|
|
|
|
|
|
############################################################################### |
12
|
1
|
|
|
1
|
|
5
|
use base qw( Exporter ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
329
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
wiki_trim |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
############################################################################### |
18
|
|
|
|
|
|
|
# Version number |
19
|
|
|
|
|
|
|
############################################################################### |
20
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
############################################################################### |
23
|
|
|
|
|
|
|
# Subroutine: wiki_trim() |
24
|
|
|
|
|
|
|
############################################################################### |
25
|
|
|
|
|
|
|
# Returns a filter which trims leading/trailing whitespace in a manner more |
26
|
|
|
|
|
|
|
# suitable for wikitext entry fields; leading blank -lines- are trimmed, as |
27
|
|
|
|
|
|
|
# well as all trailing whitespace. |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# This differs from the standard "trim" filter in that we're only trimming |
30
|
|
|
|
|
|
|
# leading blank -lines- but leave any leading whitespace on the first line; |
31
|
|
|
|
|
|
|
# those leading spaces may be important. |
32
|
|
|
|
|
|
|
############################################################################### |
33
|
|
|
|
|
|
|
sub wiki_trim { |
34
|
|
|
|
|
|
|
return sub { |
35
|
1
|
|
|
1
|
|
301
|
return _wiki_trim( shift ); |
36
|
|
|
|
|
|
|
} |
37
|
1
|
|
|
1
|
1
|
609
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _wiki_trim { |
40
|
1
|
|
|
1
|
|
3
|
my $value = shift; |
41
|
1
|
50
|
|
|
|
4
|
return unless defined $value; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# remove leading blank lines |
44
|
1
|
|
|
|
|
8
|
$value =~ s/^\s+\n//; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# remove trailing whitespace |
47
|
1
|
|
|
|
|
6
|
$value =~ s/\s+$//; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# done |
50
|
1
|
|
|
|
|
4
|
return $value; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=for stopwords wikitext |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 NAME |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Data::FormValidator::Filters::WikiTrim - Trim filter for wikitext fields |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use Data::FormValidator::Filters::WikiTrim qw(wiki_trim); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Build Data::FormValidator profile |
66
|
|
|
|
|
|
|
my $profile = { |
67
|
|
|
|
|
|
|
'required' => [qw( subject body )], |
68
|
|
|
|
|
|
|
'field_filters' => { |
69
|
|
|
|
|
|
|
'subject' => 'trim', |
70
|
|
|
|
|
|
|
'body' => wiki_trim(), |
71
|
|
|
|
|
|
|
}, |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
C provides a slightly different C |
77
|
|
|
|
|
|
|
filter than the default. Rather than trimming I leading/trailing |
78
|
|
|
|
|
|
|
whitespace, we trim all leading I and all trailing whitespace. In |
79
|
|
|
|
|
|
|
a wikitext field, leading spaces on the first line could be important so they |
80
|
|
|
|
|
|
|
need to be preserved (while leading blank lines aren't important and could be |
81
|
|
|
|
|
|
|
trimmed out). |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 METHODS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=over |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item wiki_trim() |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns a filter which trims leading/trailing whitespace in a manner more |
90
|
|
|
|
|
|
|
suitable for wikitext entry fields; leading blank -lines- are trimmed, as |
91
|
|
|
|
|
|
|
well as all trailing whitespace. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This differs from the standard "trim" filter in that we're only trimming |
94
|
|
|
|
|
|
|
leading blank -lines- but leave any leading whitespace on the first line; |
95
|
|
|
|
|
|
|
those leading spaces may be important. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=back |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AUTHOR |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Graham TerMarsch |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 COPYRIGHT |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Copyright (C) 2007, Graham TerMarsch. All Rights Reserved. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under the same |
108
|
|
|
|
|
|
|
license as Perl itself. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 SEE ALSO |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=over |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=back |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |