Verifier/Nested.pm

filter: Statementstmt 100% 49 / 49 Branchbran 68.7% 11 / 16 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 87.0% 74 / 85 CC 14 SCAR 13.9
CC
14
Cov
90%
__ANON__
5.1
__ANON__
5.1
__ANON__
5.1
CRAP 4.0
« Verifier.pm ↑ Summary Verifier/Results.pm »
1 package Data::Verifier::Nested;
2 1 $Data::Verifier::Nested::VERSION = '0.66';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: Nested profile based data verification with Moose type constraints.
6  
7 1 extends 'Data::Verifier';
8  
9  
10 ## private helper functions
11  
12 5 ▶my $_is_profile_spec = sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
13 5 my $spec = shift;
14 5 ▶ return 0 unless ref $spec eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $spec eq "HASH" 0 5 5
15 5 my @keys = grep { ref $spec->{ $_ } eq 'HASH' } keys %$spec;
16 5 ▶ ($_ eq 'dependent') && return 1 foreach @keys;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "dependent" and return 1 0 2 2
17 5 ▶ return 0 if @keys;
Branch: 1 branch
BranchTrueFalseTotal
if @keys 1 4 5
18 4 return 1;
19 1 };
20  
21 1 my $_collapse_profile;
22 2 ▶$_collapse_profile = sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
23 2 my ($profile, $acc, $prefix) = @_;
24 2 foreach my $k ( keys %$profile ) {
25 5 ▶ my $full_k = join '.' => ($prefix || (), $k);
Condition66%2/3
$prefix || ()
l!l&&r!l&&!r
230
MC/DC0%0/2
$prefix || ()
$prefix ()
Truth table66%2/3
A || B
A= $prefixB= ()
ABresult
1X1
011
000
26 5 ▶ if ( $_is_profile_spec->( $profile->{ $k } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$_is_profile_spec($profile->{$k})) { } 4 1 5
27 4 $acc->{ $full_k } = $profile->{ $k }
28 }
29 else {
30 1 ▶ (ref $profile->{ $k } eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
ref $profile->{$k} eq "HASH" or die "Can only collapse HASH refs" 1 0 1
31 || die "Can only collapse HASH refs";
32 1 $_collapse_profile->( $profile->{ $k }, $acc, $full_k );
33 }
34 }
35 1 };
36  
37 1 ▶my $collapse_profile = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 1 my ($profile) = @_;
39 1 my $acc = {};
40 1 $_collapse_profile->( $profile, $acc );
41 1 $acc;
42 1 };
43  
44 1 my $_collapse_data_for_profile;
45 4 ▶$_collapse_data_for_profile = sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
46 4 my ($profile, $data, $acc, $prefix) = @_;
47 4 foreach my $k ( keys %$data ) {
48 9 ▶ my $full_k = join '.' => ($prefix || (), $k);
Condition66%2/3
$prefix || ()
l!l&&r!l&&!r
450
MC/DC0%0/2
$prefix || ()
$prefix ()
Truth table66%2/3
A || B
A= $prefixB= ()
ABresult
1X1
011
000
49 9 ▶ if ( exists $profile->{ $full_k } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $profile->{$full_k}) { } 7 2 9
50 7 $acc->{ $full_k } = $data->{ $k }
51 }
52 else {
53 2 ▶ (ref $data->{ $k } eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
ref $data->{$k} eq "HASH" or die "Can only collapse HASH refs" 2 0 2
54 || die "Can only collapse HASH refs";
55 2 $_collapse_data_for_profile->( $profile, $data->{ $k }, $acc, $full_k );
56 }
57 }
58 1 };
59  
60 2 ▶my $collapse_data_for_profile = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
61 2 my ($profile, $data) = @_;
62 2 my $acc = {};
63 2 $_collapse_data_for_profile->( $profile, $data, $acc );
64 2 $acc;
65 1 };
66  
67 # now to the subclass ...
68  
69 1 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=2 SCAR=7.0
Pod documented
70 1 my $self = shift;
71 1 my $params = $self->SUPER::BUILDARGS( @_ );
72 # NOTE:
73 # this is required, but we don't want to
74 # make assumptions, if it is not here, then
75 # it will die later on with the right error
76 # so we can just process it if we have it.
77 # - SL
78 $params->{'profile'} = $collapse_profile->( $params->{'profile'} )
79 1 ▶ if exists $params->{'profile'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params->{"profile"} 1 0 1
80 1 $params;
81 }
82  
83 2 ▶sub verify {
Subroutine verify: called CC=1 SCAR=0.0
Pod documented
84 2 my ($self, $params, $members) = @_;
85 2 $self->SUPER::verify(
86 $collapse_data_for_profile->(
87 $self->profile,
88 $params
89 ),
90 $members
91 );
92 }
93  
94  
95 1 __PACKAGE__->meta->make_immutable;
96  
97 1 1;
98  
99 __END__
« Verifier.pm ↑ Summary Verifier/Results.pm »