| 1 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::Constraint::Regex; | ||||||||||||||||||||||||||||
| 4 | 36 | $HTML::FormFu::Constraint::Regex::VERSION = '2.09'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Regex Constraint | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 36 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 36 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 36 | extends 'HTML::FormFu::Constraint'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 36 | ▶ | use Regexp::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 36 | has common => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 14 | 36 | has regex => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 15 | 36 | has anchored => ( is => 'rw', traits => ['Chained'] ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 97 | ▶ | sub constrain_value { | ||||||||||||||||||||||||||
|
Subroutine
constrain_value: called CC=10 SCAR=23.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 97 | my ( $self, $value ) = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 97 | ▶ | return 1 if !defined $value || $value eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or $value eq ""
MC/DC100%2/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table100%3/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 84 | my $regex; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 84 | ▶ | if ( defined $self->regex ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 25 | 65 | $regex = $self->regex; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | elsif ( defined $self->common ) { | ||||||||||||||||||||||||||||
| 28 | my @common | ||||||||||||||||||||||||||||
| 29 | = ref $self->common | ||||||||||||||||||||||||||||
| 30 | 7 | ▶ | ? @{ $self->common } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | : $self->common; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 7 | $regex = shift @common; | |||||||||||||||||||||||||||
| 34 | 7 | $regex = $RE{$regex}; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 7 | for (@common) { | |||||||||||||||||||||||||||
| 37 | 14 | ▶ | $regex = $regex->{ ref $_ ? join( $;, %$_ ) : $_ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||
| 41 | 12 | $regex = qr/.*/; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 84 | ▶ | if ( $self->anchored ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 2 | $regex = qr{^$regex\z}; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 84 | my $ok = $value =~ $regex; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 84 | ▶ | return $self->not ? !$ok : $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 36 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 36 | 1; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||