Valiant/Filter/Title.pm

filter: Statementstmt 100% 16 / 16 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 87.5% 21 / 24 CC 2 SCAR 3.4
CC
2
Cov
94%
filter_each
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Valiant/Filter/Trim.pm ↑ Summary Valiant/Filter/HtmlEscape.pm »
1 package Valiant::Filter::Title;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Text::Autoformat;
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  
18 1 my $title = autoformat $value, { case => 'title' };
19  
20 1 $title =~s/[\n]//g; # Is this a bug in Text::Autoformat???
21  
22 1 return $title;
23 }
24  
25 1 1;
26  
27 =head1 NAME
28  
29 Valiant::Filter::Title - title case a string
30  
31 =head1 SYNOPSIS
32  
33 package Local::Test::User;
34  
35 use Moo;
36 use Valiant::Filters;
37  
38 has 'name' => (is=>'ro', required=>1);
39  
40 filters name => (
41 title => 1,
42 );
43  
44 my $user = Local::Test::User->new(name=>'john napiorkowski');
45  
46 print $user->name; # 'John Napiorkowski'
47
48 =head1 DESCRIPTION
49  
50 This is a very simple filter that takes no paramters and just does title case (that is
51 the first letter of each word becomes upper case) on the
52 value of the attribute.
53  
54 =head1 SEE ALSO
55
56 L<Valiant>, L<Valiant::Filter>, L<Valiant::Validator::Filter>.
57  
58 =head1 AUTHOR
59
60 See L<Valiant>
61
62 =head1 COPYRIGHT & LICENSE
63
64 See L<Valiant>
65  
66 =cut
« Valiant/Filter/Trim.pm ↑ Summary Valiant/Filter/HtmlEscape.pm »