| 1 | package Valiant::Filter::Trim; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use Valiant::Util 'throw_exception'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | with 'Valiant::Filter::Each'; | |||||||||
| 7 | |||||||||||
| 8 | 5 | ▶ | sub normalize_shortcut { | ||||||||
|
Subroutine
normalize_shortcut: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 9 | 5 | my ($class, $arg) = @_; | |||||||||
| 10 | 5 | return +{ }; | |||||||||
| 11 | } | ||||||||||
| 12 | |||||||||||
| 13 | 7 | ▶ | sub filter_each { | ||||||||
|
Subroutine
filter_each: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 14 | 7 | my ($self, $class, $attrs, $attribute_name) = @_; | |||||||||
| 15 | 7 | my $value = $attrs->{$attribute_name}; | |||||||||
| 16 | 7 | ▶ | return unless defined $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | 7 | $value =~ s/^\s+|\s+$//g; | |||||||||
| 19 | 7 | return $value; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 4 | 1; | |||||||||
| 23 | |||||||||||
| 24 | =head1 NAME | ||||||||||
| 25 | |||||||||||
| 26 | Valiant::Validator::With - Validate using a coderef or method | ||||||||||
| 27 | |||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||
| 29 | |||||||||||
| 30 | package Local::Test::User; | ||||||||||
| 31 | |||||||||||
| 32 | use Moo; | ||||||||||
| 33 | use Valiant::Filters; | ||||||||||
| 34 | |||||||||||
| 35 | has 'name' => (is=>'ro', required=>1); | ||||||||||
| 36 | |||||||||||
| 37 | filters name => ( | ||||||||||
| 38 | trim => 1; | ||||||||||
| 39 | ); | ||||||||||
| 40 | |||||||||||
| 41 | my $user = Local::Test::User->new(name=>' john '); | ||||||||||
| 42 | |||||||||||
| 43 | print $user->name; # 'john' | ||||||||||
| 44 | |||||||||||
| 45 | |||||||||||
| 46 | =head1 DESCRIPTION | ||||||||||
| 47 | |||||||||||
| 48 | Trims whitespace from the start and end of a string value. | ||||||||||
| 49 | |||||||||||
| 50 | =head1 SEE ALSO | ||||||||||
| 51 | |||||||||||
| 52 | L<Valiant>, L<Valiant::Filter>, L<Valiant::Filter::Each>. | ||||||||||
| 53 | |||||||||||
| 54 | =head1 AUTHOR | ||||||||||
| 55 | |||||||||||
| 56 | See L<Valiant> | ||||||||||
| 57 | |||||||||||
| 58 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 59 | |||||||||||
| 60 | See L<Valiant> | ||||||||||
| 61 | |||||||||||
| 62 | =cut | ||||||||||