Brick/Filters.pm

filter: Statementstmt 21.1% 11 / 52 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 23.0% 3 / 13 Podpod n/a totaltotal 13.7% 14 / 102 CC 17 SCAR 22.9
CC
17
Cov
14%
__ANON__
20.0
__ANON__
12.0
__ANON__
12.0
CRAP 9.9
« Brick/Bucket.pm ↑ Summary Brick/Profile.pm »
1 package Brick::Filters;
2  
3 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 $VERSION = '0.904';
7  
8 package Brick::Bucket;
9 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 0 ▶ my( $bucket, $setup ) = @_;
Subroutine _uppercase: not called CC=2 SCAR=17.9
40  
41 0 my @caller = $bucket->__caller_chain_as_list();
42  
43 $bucket->add_to_bucket( {
44 name => $setup->{name} || $caller[0]{'sub'},
45 description => "filter: uppercase the input",
46 code => sub {
47 0 ▶ foreach my $f ( @{ $setup->{filter_fields} } )
Subroutine __ANON__: not called CC=3 SCAR=24.8
48 {
49 0 ▶ next unless exists $_[0]->{ $f };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[0]{$f} 0 0 0
50 0 $_[0]->{ $f } = uc $_[0]->{ $f };
51 }
52 0 return 1;
53 },
54 0 ▶ } );
Condition0%0/3
$setup->{'name'} || $caller[0]{'sub'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$setup->{'name'} || $caller[0]{'sub'}
$setup->{'name'} $caller[0]{'sub'}
Truth table0%0/3
A || B
A= $setup->{'name'}B= $caller[0]{'sub'}
ABresult
1X1
011
000
55 }
56  
57 =item _lowercase( HASHREF )
58  
59 This modifies the input data permanently. It removes the non-digits
60 from the specified value in filter_fields. The value is no longer tainted
61 after this runs. It works on all of the fields.
62  
63 filter_fields
64  
65 This filter always succeeds, so it will not generate an validation
66 error.
67  
68 =cut
69  
70 sub _lowercase {
71 0 ▶ my( $bucket, $setup ) = @_;
Subroutine _lowercase: not called CC=2 SCAR=17.9
72  
73 0 my @caller = $bucket->__caller_chain_as_list();
74  
75 $bucket->add_to_bucket( {
76 name => $setup->{name} || $caller[0]{'sub'},
77 description => "filter: uppercase the input",
78 code => sub {
79 0 ▶ foreach my $f ( @{ $setup->{filter_fields} } )
Subroutine __ANON__: not called CC=3 SCAR=24.8
80 {
81 0 ▶ next unless exists $_[0]->{ $f };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[0]{$f} 0 0 0
82 0 $_[0]->{ $f } = lc $_[0]->{ $f };
83 }
84 0 return 1;
85 },
86 0 ▶ } );
Condition0%0/3
$setup->{'name'} || $caller[0]{'sub'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$setup->{'name'} || $caller[0]{'sub'}
$setup->{'name'} $caller[0]{'sub'}
Truth table0%0/3
A || B
A= $setup->{'name'}B= $caller[0]{'sub'}
ABresult
1X1
011
000
87 }
88  
89 =item _remove_non_digits( HASHREF )
90  
91 This modifies the input data permanently. It removes the non-digits
92 from the specified value in filter_fields. The value is no longer tainted
93 after this runs. It works on all of the fields.
94  
95 filter_fields
96  
97 This filter always succeeds, so it will not generate an validation
98 error.
99  
100 =cut
101  
102 sub _remove_non_digits {
103 0 ▶ my( $bucket, $setup ) = @_;
Subroutine _remove_non_digits: not called CC=2 SCAR=17.9
104  
105 0 my @caller = $bucket->__caller_chain_as_list();
106  
107 $bucket->add_to_bucket( {
108 name => $setup->{name} || $caller[0]{'sub'},
109 description => "filter: remove non-digits",
110 code => sub {
111 0 ▶ foreach my $f ( @{ $setup->{filter_fields} } )
Subroutine __ANON__: not called CC=4 SCAR=30.0
112 {
113 0 ▶ next unless exists $_[0]->{ $f };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[0]{$f} 0 0 0
114 0 $_[0]->{ $f } =~ tr/0-9//cd;
115 $_[0]->{ $f } =
116 0 ▶ $_[0]->{ $f } =~ m/([0-9]*)/
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{$f} =~ /([0-9]*)/ ? : 0 0 0
117 ?
118 $1
119 :
120 '';
121 }
122 0 return 1;
123 },
124 0 ▶ } );
Condition0%0/3
$setup->{'name'} || $caller[0]{'sub'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$setup->{'name'} || $caller[0]{'sub'}
$setup->{'name'} $caller[0]{'sub'}
Truth table0%0/3
A || B
A= $setup->{'name'}B= $caller[0]{'sub'}
ABresult
1X1
011
000
125 }
126  
127 =item _remove_whitespace( HASHREF )
128  
129 This modifies the input data permanently. It removes the whitespace
130 from the specified value in filter_fields. The value is still tainted
131 after this runs.
132  
133 filter_fields
134  
135 This filter always succeeds, so it will not generate an error.
136  
137 =cut
138  
139 sub _remove_whitespace {
140 0 ▶ my( $bucket, $setup ) = @_;
Subroutine _remove_whitespace: not called CC=2 SCAR=17.9
141  
142 0 my @caller = $bucket->__caller_chain_as_list();
143  
144 $bucket->add_to_bucket( {
145 name => $setup->{name} || $caller[0]{'sub'},
146 description => "filter: remove whitespace",
147 code => sub {
148 0 ▶ foreach my $f ( @{ $setup->{filter_fields} } )
Subroutine __ANON__: not called CC=3 SCAR=24.8
149 {
150 0 ▶ next unless exists $_[0]->{ $f };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $_[0]{$f} 0 0 0
151 0 $_[0]->{ $f } =~ tr/\n\r\t\f //d;
152 }
153 },
154 0 ▶ } );
Condition0%0/3
$setup->{'name'} || $caller[0]{'sub'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$setup->{'name'} || $caller[0]{'sub'}
$setup->{'name'} $caller[0]{'sub'}
Truth table0%0/3
A || B
A= $setup->{'name'}B= $caller[0]{'sub'}
ABresult
1X1
011
000
155 }
156  
157 =item _remove_extra_fields( HASHREF )
158  
159 This modifies the input data permanently. It removes any fields in
160 the input that are not also in the 'filter_fields' value in HASHREF.
161  
162 filter_fields
163  
164 This filter always succeeds, so it will not generate an error.
165  
166 =cut
167  
168 sub _remove_extra_fields {
169 0 ▶ my( $bucket, $setup ) = @_;
Subroutine _remove_extra_fields: not called CC=2 SCAR=17.9
170  
171 0 my @caller = $bucket->__caller_chain_as_list();
172  
173 0 my %allowed = map { $_, 1 } @{ $setup->{filter_fields} };
174  
175 $bucket->add_to_bucket( {
176 name => $setup->{name} || $caller[0]{'sub'},
177 description => "filter: remove extra fields",
178 code => sub {
179 0 ▶ foreach my $f ( keys % {$_[0] } )
Subroutine __ANON__: not called CC=3 SCAR=24.8
180 {
181 0 ▶ delete $_[0]->{$f} unless exists $allowed{$f};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $allowed{$f} 0 0 0
182 }
183 },
184 0 ▶ } );
Condition0%0/3
$setup->{'name'} || $caller[0]{'sub'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$setup->{'name'} || $caller[0]{'sub'}
$setup->{'name'} $caller[0]{'sub'}
Truth table0%0/3
A || B
A= $setup->{'name'}B= $caller[0]{'sub'}
ABresult
1X1
011
000
185 }
186  
187 =back
188  
189 =head1 TO DO
190  
191 TBA
192  
193 =head1 SEE ALSO
194  
195 TBA
196  
197 =head1 SOURCE AVAILABILITY
198  
199 This source is in Github:
200  
201 https://github.com/briandfoy/brick
202  
203 =head1 AUTHOR
204  
205 brian d foy, C<< <briandfoy@pobox.com> >>
206  
207 =head1 COPYRIGHT
208  
209 Copyright © 2007-2025, brian d foy <briandfoy@pobox.com>. All rights reserved.
210  
211 You may redistribute this under the terms of the Artistic License 2.0.
212  
213 =cut
214  
215 5 1;
« Brick/Bucket.pm ↑ Summary Brick/Profile.pm »