| 1 | package Data::Validation::Filters; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Data::Validation::Constants qw( EXCEPTION_CLASS HASH TRUE ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Data::Validation::Utils qw( load_class ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Unexpected::Types qw( Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | has 'method' => is => 'ro', isa => Str, required => TRUE; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | has 'pattern' => is => 'ro', isa => Str; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | has 'replace' => is => 'ro', isa => Str; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 15 | ▶ | sub new_from_method { | ||||||||||||||||||||||||||
|
Subroutine
new_from_method: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 15 | my ($class, $attr) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 15 | ▶ | $class->can( $attr->{method} ) and return $class->new( $attr ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | return (load_class $class, 'filter', $attr->{method})->new( $attr ); | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 14 | ▶ | sub filter { | ||||||||||||||||||||||||||
|
Subroutine
filter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 14 | my ($self, $v) = @_; my $method = $self->method; return $self->$method( $v ); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 14 | ▶ | around 'filter' => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 29 | 14 | ▶ | my ($orig, $self, $v) = @_; return defined $v ? $orig->( $self, $v ) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 1 | }; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Builtin filter methods | ||||||||||||||||||||||||||||
| 33 | 1 | ▶ | sub filterEscapeHTML { | ||||||||||||||||||||||||||
|
Subroutine
filterEscapeHTML: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 1 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | $v =~ s{ &(?!(amp|lt|gt|quot);) }{&}gmx; | |||||||||||||||||||||||||||
| 37 | 1 | $v =~ s{ < }{<}gmx; | |||||||||||||||||||||||||||
| 38 | 1 | $v =~ s{ > }{>}gmx; | |||||||||||||||||||||||||||
| 39 | 1 | $v =~ s{ \" }{"}gmx; | |||||||||||||||||||||||||||
| 40 | 1 | return $v; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub filterLowerCase { | ||||||||||||||||||||||||||
|
Subroutine
filterLowerCase: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 1 | my ($self, $v) = @_; return lc $v; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | ▶ | sub filterNonNumeric { | ||||||||||||||||||||||||||
|
Subroutine
filterNonNumeric: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 2 | my ($self, $v) = @_; $v =~ s{ \D+ }{}gmx; return $v; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub filterReplaceRegex { | ||||||||||||||||||||||||||
|
Subroutine
filterReplaceRegex: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 1 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | my $pattern = $self->pattern or return $v; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my $replace = defined $self->replace ? $self->replace : q(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | $v =~ s{ $pattern }{$replace}gmx; | |||||||||||||||||||||||||||
| 58 | 1 | return $v; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | sub filterTitleCase { | ||||||||||||||||||||||||||
|
Subroutine
filterTitleCase: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 1 | my ($self, $v) = @_; my @words = split ' ', $v, -1; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 1 | return join ' ', map { ucfirst $_ } @words; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub filterTrimBoth { | ||||||||||||||||||||||||||
|
Subroutine
filterTrimBoth: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 2 | my ($self, $v) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | $v =~ s{ \A \s+ }{}mx; $v =~ s{ \s+ \z }{}mx; | |||||||||||||||||||||||||||
| 71 | 2 | return $v; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | ▶ | sub filterUpperCase { | ||||||||||||||||||||||||||
|
Subroutine
filterUpperCase: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 2 | my ($self, $v) = @_; return uc $v; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub filterUCFirst { | ||||||||||||||||||||||||||
|
Subroutine
filterUCFirst: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 1 | my ($self, $v) = @_; return ucfirst $v; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | ▶ | sub filterWhiteSpace { | ||||||||||||||||||||||||||
|
Subroutine
filterWhiteSpace: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 1 | my ($self, $v) = @_; $v =~ s{ \s+ }{}gmx; return $v; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | ▶ | sub filterZeroLength { | ||||||||||||||||||||||||||
|
Subroutine
filterZeroLength: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 2 | ▶ | return defined $_[ 1 ] && length $_[ 1 ] ? $_[ 1 ] : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_[1] and length $_[1]
MC/DC50%1/2
defined $_[1] and length $_[1]
defined $_[1]
length $_[1]
Truth table66%2/3
A and B
A= defined $_[1]B= length $_[1]
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | 1; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||