TreeValidator/Constraints.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 12 / 12 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 97.4% 77 / 79 CC 10 SCAR 10.4
CC
10
Cov
98%
__ANON__
6.0
_required
3.0
__ANON__
2.0
CRAP 2.8
« TreeValidator/Leaf.pm ↑ Summary TreeValidator.pm »
1 package Data::TreeValidator::Constraints;
2 {
3 5 $Data::TreeValidator::Constraints::VERSION = '0.04';
4 }
5 # ABSTRACT: A collection of constraints for validating data
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶use Data::TreeValidator::Util qw( fail_constraint );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Set::Object qw( set );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 exports => [ qw( length options required type ) ]
14 5 };
15  
16 6 ▶sub required { \&_required }
Subroutine required: called CC=1 SCAR=0.0
Pod documented
17 17 ▶sub _required {
Subroutine _required: called CC=3 SCAR=11.0
18 17 local $_ = shift;
19 17 ▶ fail_constraint("Required") unless defined $_ && "$_" ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ and "$_" ne "" 2 15 17
Condition100%3/3
defined $_ and "$_" ne ""
!ll&&!rl&&r
1115
MC/DC100%2/2
defined $_ and "$_" ne ""
defined $_ "$_" ne ""
Truth table100%3/3
A and B
A= defined $_B= "$_" ne ""
ABresult
0X0
100
111
20 }
21  
22 2 ▶sub length {
Subroutine length: called CC=1 SCAR=0.0
Pod documented
23 2 my %args = @_;
24 2 my ($min, $max) = @args{qw( min max )};
25 8 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=17.9
26 8 my ($input) = @_;
27 8 ▶ my $length = defined $input ? length($input) : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $input ? : 7 1 8
28  
29 fail_constraint("Input must be longer than $min characters")
30 8 ▶ if exists $args{min} && $length < $min;
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"min"} and $length < $min 3 5 8
Condition100%3/3
exists $args{"min"} and $length < $min
!ll&&!rl&&r
323
MC/DC100%2/2
exists $args{"min"} and $length < $min
exists $args{"min"} $length < $min
Truth table100%3/3
A and B
A= exists $args{"min"}B= $length < $min
ABresult
0X0
100
111
31 fail_constraint("Input must be shorter than $max characters")
32 5 ▶ if exists $args{max} && $length > $max;
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"max"} and $length > $max 2 3 5
Condition66%2/3
exists $args{"max"} and $length > $max
!ll&&!rl&&r
032
MC/DC50%1/2
exists $args{"max"} and $length > $max
exists $args{"max"} $length > $max
Truth table66%2/3
A and B
A= exists $args{"max"}B= $length > $max
ABresult
0X0
100
111
33 }
34 2 }
35  
36 2 ▶sub options {
Subroutine options: called CC=1 SCAR=0.0
Pod documented
37 2 my $valid = set(@_);
38 9 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
39 9 my ($input) = @_;
40 9 ▶ fail_constraint("Input must be a valid set member")
Branch: 1 branch
BranchTrueFalseTotal
unless $valid->contains($input) 6 3 9
41 unless $valid->contains($input);
42 2 };
43 }
44  
45 2 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
46 2 my $type = shift;
47 13 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
48 13 ▶ fail_constraint('Input must be of type: ' . $type->name . '"')
Branch: 1 branch
BranchTrueFalseTotal
unless $type->check(@_) 7 6 13
49 unless $type->check(@_);
50 2 };
51 }
52  
53 5 1;
54  
55  
56 __END__
« TreeValidator/Leaf.pm ↑ Summary TreeValidator.pm »