blib/lib/Data/FormValidator/Filters/WikiTrim.pm

filter: Statementstmt 100% 19 / 19 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 96.4% 27 / 28 CC 2 SCAR 2.5
CC
2
Cov
95%
_wiki_trim
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
↑ Summary
1 package Data::FormValidator::Filters::WikiTrim;
2  
3 ###############################################################################
4 # Required inclusions.
5 ###############################################################################
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 ###############################################################################
10 # Export a few of our methods
11 ###############################################################################
12 2 ▶use base qw( Exporter );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 our @EXPORT_OK = qw(
14 wiki_trim
15 );
16  
17 ###############################################################################
18 # Version number
19 ###############################################################################
20 2 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 1 ▶sub wiki_trim {
Subroutine wiki_trim: called CC=1 SCAR=0.0
Pod documented
34 1 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
35 1 return _wiki_trim( shift );
36 }
37 1 }
38  
39 1 ▶sub _wiki_trim {
Subroutine _wiki_trim: called CC=2 SCAR=7.0
40 1 my $value = shift;
41 1 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1 1
42  
43 # remove leading blank lines
44 1 $value =~ s/^\s+\n//;
45  
46 # remove trailing whitespace
47 1 $value =~ s/\s+$//;
48  
49 # done
50 1 return $value;
51 }
52  
53 2 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<Data::FormValidator::Filters::WikiTrim> provides a slightly different C<trim>
77 filter than the default. Rather than trimming I<all> leading/trailing
78 whitespace, we trim all leading I<blank lines> 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 <cpan@howlingfrog.com>
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<Data::FormValidator>
115  
116 =back
117  
118 =cut
↑ Summary