TreeValidator/Leaf.pm

filter: Statementstmt 100% 47 / 47 Branchbran 83.3% 5 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 1 / 1 totaltotal 98.6% 71 / 72 CC 7 SCAR 11.7
CC
7
Cov
98%
process
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
↑ Summary TreeValidator/Constraints.pm »
1 package Data::TreeValidator::Leaf;
2 {
3 4 $Data::TreeValidator::Leaf::VERSION = '0.04';
4 }
5 # ABSTRACT: Represents a single leaf node in the validation tree specification
6 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Data::TreeValidator::Types qw( Constraint Transformation Value );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use MooseX::Types::Moose qw( ArrayRef CodeRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶use aliased 'Data::TreeValidator::Result::Leaf' => 'Result';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 with 'Data::TreeValidator::Node';
19  
20 has 'constraints' => (
21 isa => ArrayRef[Constraint],
22 10 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
23 4 traits => [ 'Array' ],
24 handles => {
25 constraints => 'elements',
26 add_constraint => 'push',
27 }
28 );
29  
30 has 'transformations' => (
31 isa => ArrayRef[Transformation],
32 traits => [ 'Array' ],
33 16 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 4 handles => {
35 transformations => 'elements',
36 add_transformation => 'push',
37 }
38 );
39  
40 27 ▶sub process {
Subroutine process: called CC=7 SCAR=19.5
Pod documented
41 27 my $self = shift;
42 27 my ($input) = pos_validated_list([ shift ],
43 { isa => Value }
44 );
45 27 my %args = @_;
46  
47 27 ▶ my $process = $input // $args{initialize};
Condition100%3/3
$input // $args{"initialize"}
l!l&&r!l&&!r
2412
MC/DC100%2/2
$input // $args{"initialize"}
$input $args{"initialize"}
Truth table100%3/3
A // B
A= $inputB= $args{"initialize"}
ABresult
1X1
011
000
48  
49 27 my @errors;
50 27 for my $constraint ($self->constraints) {
51 21 ▶ if (is_CodeRef($constraint)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_CodeRef($constraint)) 21 0 21
52 21 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
53 21 $constraint->( $process );
54 }
55 3 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
56 3 push @errors, $_;
57 }
58 21 }
59 }
60  
61 27 my $clean;
62 27 ▶ if (@errors == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors == 0) 24 3 27
63 24 $clean = $process;
64 24 for my $transformation ($self->transformations) {
65 3 $clean = $transformation->( $clean );
66 }
67 }
68  
69 27 ▶ return Result->new(
Branch: 1 branch
BranchTrueFalseTotal
@errors == 0 ? : 24 3 27
70 input => $input,
71 errors => \@errors,
72 @errors == 0 ? (clean => $clean) : ()
73 );
74 }
75  
76 4 1;
77  
78  
79 __END__
↑ Summary TreeValidator/Constraints.pm »