line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Verifier::Filters; |
2
|
|
|
|
|
|
|
$Data::Verifier::Filters::VERSION = '0.61'; |
3
|
17
|
|
|
17
|
|
67
|
use strict; |
|
17
|
|
|
|
|
21
|
|
|
17
|
|
|
|
|
460
|
|
4
|
17
|
|
|
17
|
|
61
|
use warnings; |
|
17
|
|
|
|
|
17
|
|
|
17
|
|
|
|
|
3573
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Filters for values |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub collapse { |
10
|
2
|
|
|
2
|
1
|
2
|
my ($self, $val) = @_; |
11
|
2
|
50
|
|
|
|
3
|
return $val if not defined $val; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
|
|
8
|
$val =~ s/\s+/ /g; |
14
|
2
|
|
|
|
|
4
|
return $val; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub flatten { |
19
|
3
|
|
|
3
|
1
|
5
|
my ($self, $val) = @_; |
20
|
3
|
50
|
|
|
|
6
|
return $val if not defined $val; |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
12
|
$val =~ s/\s//g; |
23
|
3
|
|
|
|
|
10
|
return $val; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub lower { |
28
|
1
|
|
|
1
|
1
|
1
|
my ($self, $val) = @_; |
29
|
1
|
50
|
|
|
|
4
|
return $val if not defined $val; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
3
|
return lc($val); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub trim { |
36
|
10
|
|
|
10
|
1
|
11
|
my ($self, $val) = @_; |
37
|
10
|
100
|
|
|
|
15
|
return $val if not defined $val; |
38
|
|
|
|
|
|
|
|
39
|
9
|
|
|
|
|
25
|
$val =~ s/^\s+|\s+$//g; |
40
|
|
|
|
|
|
|
|
41
|
9
|
|
|
|
|
23
|
return $val; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub upper { |
46
|
2
|
|
|
2
|
1
|
3
|
my ($self, $val) = @_; |
47
|
2
|
50
|
|
|
|
3
|
return $val if not defined $val; |
48
|
|
|
|
|
|
|
|
49
|
2
|
|
|
|
|
6
|
return uc($val); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=pod |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Data::Verifier::Filters - Filters for values |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 VERSION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
version 0.61 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SYNOPSIS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Data::Verifier; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $dv = Data::Verifier->new(profile => { |
71
|
|
|
|
|
|
|
name => { |
72
|
|
|
|
|
|
|
type => 'Str', |
73
|
|
|
|
|
|
|
filters => [ qw(collapse trim) ] |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
}); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$dv->verify({ name => ' foo bar '}); |
78
|
|
|
|
|
|
|
$dv->get_value('name'); # 'foo bar' |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 CUSTOM FILTERS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Adding a custom filter may be done by providing a coderef as one of the |
83
|
|
|
|
|
|
|
filters: |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Remove all whitespace |
86
|
|
|
|
|
|
|
my $sub = sub { my ($val) = @_; $val =~ s/\s//g; $val } |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$dv->verify({ |
89
|
|
|
|
|
|
|
name => { |
90
|
|
|
|
|
|
|
type => 'Str' |
91
|
|
|
|
|
|
|
filters => [ $sub ] |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
}); |
94
|
|
|
|
|
|
|
$dv->get_value('name'); # No whitespace! |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 METHODS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 collapse |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Collapses all consecutive whitespace into a single space |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 flatten |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Removes B<all whitespace>. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 lower |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Converts the value to lowercase. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 trim |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Removes leading and trailing whitespace |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 upper |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Converts the value to uppercase. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 AUTHOR |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Cory G Watson <gphat@cpan.org> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Cold Hard Code, LLC. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
127
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |