lib/HTML/FormFu/Constraint/Regex.pm

filter: Statementstmt 100% 35 / 35 Branchbran 92.8% 13 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 96.6% 58 / 60 CC 10 SCAR 20.1
CC
10
Cov
98%
constrain_value
10.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.4
« lib/HTML/FormFu/Element/Checkboxgroup.pm ↑ Summary lib/HTML/FormFu/Inflator/CompoundDateTime.pm »
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
BranchTrueFalseTotal
if not defined $value or $value eq "" 13 84 97
Condition100%3/3
not defined $value or $value eq ""
l!l&&r!l&&!r
9484
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 ""
ABresult
1X1
011
000
21  
22 84 my $regex;
23  
24 84 ▶ if ( defined $self->regex ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->regex) { } 65 19 84
elsif (defined $self->common) { } 7 12 19
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
BranchTrueFalseTotal
ref $self->common ? : 7 0 7
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
BranchTrueFalseTotal
ref $_ ? : 7 7 14
38 }
39 }
40 else {
41 12 $regex = qr/.*/;
42 }
43  
44 84 ▶ if ( $self->anchored ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->anchored) 2 82 84
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
BranchTrueFalseTotal
$self->not ? : 6 78 84
51 }
52  
53 36 __PACKAGE__->meta->make_immutable;
54  
55 36 1;
56  
57 __END__
« lib/HTML/FormFu/Element/Checkboxgroup.pm ↑ Summary lib/HTML/FormFu/Inflator/CompoundDateTime.pm »