line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Brick::Filters; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
28
|
use base qw(Exporter); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
415
|
|
4
|
5
|
|
|
5
|
|
27
|
use vars qw($VERSION); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
213
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = '0.902'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Brick::Bucket; |
9
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
3265
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=encoding utf8 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Brick::Filters - do something to the input data |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Brick; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over 4 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item _uppercase( HASHREF ) |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This modifies the input data permanently. It removes the non-digits |
28
|
|
|
|
|
|
|
from the specified value in filter_fields. The value is no longer tainted |
29
|
|
|
|
|
|
|
after this runs. It works on all of the fields. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
filter_fields |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This filter always succeeds, so it will not generate an validation |
34
|
|
|
|
|
|
|
error. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _uppercase |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
0
|
|
|
my( $bucket, $setup ) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my @caller = $bucket->__caller_chain_as_list(); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$bucket->add_to_bucket( { |
45
|
|
|
|
|
|
|
name => $setup->{name} || $caller[0]{'sub'}, |
46
|
|
|
|
|
|
|
description => "filter: uppercase the input", |
47
|
|
|
|
|
|
|
code => sub { |
48
|
0
|
|
|
0
|
|
|
foreach my $f ( @{ $setup->{filter_fields} } ) |
|
0
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
{ |
50
|
0
|
0
|
|
|
|
|
next unless exists $_[0]->{ $f }; |
51
|
0
|
|
|
|
|
|
$_[0]->{ $f } = uc $_[0]->{ $f }; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
return 1; |
54
|
|
|
|
|
|
|
}, |
55
|
0
|
|
0
|
|
|
|
} ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item _lowercase( HASHREF ) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This modifies the input data permanently. It removes the non-digits |
61
|
|
|
|
|
|
|
from the specified value in filter_fields. The value is no longer tainted |
62
|
|
|
|
|
|
|
after this runs. It works on all of the fields. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
filter_fields |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This filter always succeeds, so it will not generate an validation |
67
|
|
|
|
|
|
|
error. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _lowercase |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
0
|
|
|
my( $bucket, $setup ) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my @caller = $bucket->__caller_chain_as_list(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$bucket->add_to_bucket( { |
78
|
|
|
|
|
|
|
name => $setup->{name} || $caller[0]{'sub'}, |
79
|
|
|
|
|
|
|
description => "filter: uppercase the input", |
80
|
|
|
|
|
|
|
code => sub { |
81
|
0
|
|
|
0
|
|
|
foreach my $f ( @{ $setup->{filter_fields} } ) |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
{ |
83
|
0
|
0
|
|
|
|
|
next unless exists $_[0]->{ $f }; |
84
|
0
|
|
|
|
|
|
$_[0]->{ $f } = lc $_[0]->{ $f }; |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
return 1; |
87
|
|
|
|
|
|
|
}, |
88
|
0
|
|
0
|
|
|
|
} ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item _remove_non_digits( HASHREF ) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This modifies the input data permanently. It removes the non-digits |
94
|
|
|
|
|
|
|
from the specified value in filter_fields. The value is no longer tainted |
95
|
|
|
|
|
|
|
after this runs. It works on all of the fields. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
filter_fields |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This filter always succeeds, so it will not generate an validation |
100
|
|
|
|
|
|
|
error. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _remove_non_digits |
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
0
|
|
|
my( $bucket, $setup ) = @_; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
my @caller = $bucket->__caller_chain_as_list(); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$bucket->add_to_bucket( { |
111
|
|
|
|
|
|
|
name => $setup->{name} || $caller[0]{'sub'}, |
112
|
|
|
|
|
|
|
description => "filter: remove non-digits", |
113
|
|
|
|
|
|
|
code => sub { |
114
|
0
|
|
|
0
|
|
|
foreach my $f ( @{ $setup->{filter_fields} } ) |
|
0
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
{ |
116
|
0
|
0
|
|
|
|
|
next unless exists $_[0]->{ $f }; |
117
|
0
|
|
|
|
|
|
$_[0]->{ $f } =~ tr/0-9//cd; |
118
|
|
|
|
|
|
|
$_[0]->{ $f } = |
119
|
0
|
0
|
|
|
|
|
$_[0]->{ $f } =~ m/([0-9]*)/ |
120
|
|
|
|
|
|
|
? |
121
|
|
|
|
|
|
|
$1 |
122
|
|
|
|
|
|
|
: |
123
|
|
|
|
|
|
|
''; |
124
|
|
|
|
|
|
|
} |
125
|
0
|
|
|
|
|
|
return 1; |
126
|
|
|
|
|
|
|
}, |
127
|
0
|
|
0
|
|
|
|
} ); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item _remove_whitespace( HASHREF ) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This modifies the input data permanently. It removes the whitespace |
133
|
|
|
|
|
|
|
from the specified value in filter_fields. The value is still tainted |
134
|
|
|
|
|
|
|
after this runs. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
filter_fields |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This filter always succeeds, so it will not generate an error. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub _remove_whitespace |
143
|
|
|
|
|
|
|
{ |
144
|
0
|
|
|
0
|
|
|
my( $bucket, $setup ) = @_; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my @caller = $bucket->__caller_chain_as_list(); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
$bucket->add_to_bucket( { |
149
|
|
|
|
|
|
|
name => $setup->{name} || $caller[0]{'sub'}, |
150
|
|
|
|
|
|
|
description => "filter: remove whitespace", |
151
|
|
|
|
|
|
|
code => sub { |
152
|
0
|
|
|
0
|
|
|
foreach my $f ( @{ $setup->{filter_fields} } ) |
|
0
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
{ |
154
|
0
|
0
|
|
|
|
|
next unless exists $_[0]->{ $f }; |
155
|
0
|
|
|
|
|
|
$_[0]->{ $f } =~ tr/\n\r\t\f //d; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
}, |
158
|
0
|
|
0
|
|
|
|
} ); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item _remove_extra_fields( HASHREF ) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This modifies the input data permanently. It removes any fields in |
164
|
|
|
|
|
|
|
the input that are not also in the 'filter_fields' value in HASHREF. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
filter_fields |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This filter always succeeds, so it will not generate an error. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub _remove_extra_fields |
173
|
|
|
|
|
|
|
{ |
174
|
0
|
|
|
0
|
|
|
my( $bucket, $setup ) = @_; |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
my @caller = $bucket->__caller_chain_as_list(); |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my %allowed = map { $_, 1 } @{ $setup->{filter_fields} }; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
$bucket->add_to_bucket( { |
181
|
|
|
|
|
|
|
name => $setup->{name} || $caller[0]{'sub'}, |
182
|
|
|
|
|
|
|
description => "filter: remove extra fields", |
183
|
|
|
|
|
|
|
code => sub { |
184
|
0
|
|
|
0
|
|
|
foreach my $f ( keys % {$_[0] } ) |
|
0
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
{ |
186
|
0
|
0
|
|
|
|
|
delete $_[0]->{$f} unless exists $allowed{$f}; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
}, |
189
|
0
|
|
0
|
|
|
|
} ); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 TO DO |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
TBA |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 SEE ALSO |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
TBA |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This source is in Github: |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
https://github.com/briandfoy/brick |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 AUTHOR |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
brian d foy, C<< >> |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 COPYRIGHT |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Copyright © 2007-2022, brian d foy . All rights reserved. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
You may redistribute this under the terms of the Artistic License 2.0. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |