Valiant/Filter/Collapse.pm

filter: Statementstmt 100% 15 / 15 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 86.9% 20 / 23 CC 2 SCAR 3.4
CC
2
Cov
94%
filter_each
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Valiant/Filter/Lower.pm ↑ Summary Valiant/Filter/Trim.pm »
1 package Valiant::Filter::Collapse;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Valiant::Util 'throw_exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 with 'Valiant::Filter::Each';
7  
8 1 ▶sub normalize_shortcut {
Subroutine normalize_shortcut: called CC=1 SCAR=0.0
Pod undocumented
9 1 my ($class, $arg) = @_;
10 1 return +{ };
11 }
12  
13 1 ▶sub filter_each {
Subroutine filter_each: called CC=2 SCAR=7.0
Pod undocumented
14 1 my ($self, $class, $attrs, $attribute_name) = @_;
15 1 my $value = $attrs->{$attribute_name};
16 1 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 1 1
17 1 $value =~ s/[\h\v]+/ /g;
18 1 return $value;
19 }
20  
21 1 1;
22  
23 =head1 NAME
24  
25 Valiant::Filter::Collapse - collapse whitespace
26  
27 =head1 SYNOPSIS
28  
29 package Local::Test::User;
30  
31 use Moo;
32 use Valiant::Filters;
33  
34 has 'name' => (is=>'ro', required=>1);
35  
36 filters name => (
37 collapse => 1,
38 );
39  
40 my $user = Local::Test::User->new(name=>'john james napiorkowski');
41  
42 print $user->name; # 'john james napiorkowski'
43
44 =head1 DESCRIPTION
45  
46 Given a string collapse all whitespace to a space 'space'. This will not remove
47 whitespace at the start/end of a string, merely collapse it to a single space (
48 see L<Valiant::Filter::Trim>)
49 =head1 SEE ALSO
50
51 L<Valiant>, L<Valiant::Filter>, L<Valiant::Validator::Filter>.
52  
53 =head1 AUTHOR
54
55 See L<Valiant>
56
57 =head1 COPYRIGHT & LICENSE
58
59 See L<Valiant>
60  
61 =cut
« Valiant/Filter/Lower.pm ↑ Summary Valiant/Filter/Trim.pm »