Nested/ProfileProvider.pm

filter: Statementstmt 84.2% 48 / 57 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 12 / 18 Podpod 0.0% 0 / 3 totaltotal 78.8% 71 / 90 CC 8 SCAR 9.6
CC
8
Cov
86%
get_profile
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.6
« Nested/Validator/DateTime.pm ↑ Summary Nested/Validator/Bool.pm »
1 package FormValidator::Nested::ProfileProvider;
2 18 ▶use Any::Moose '::Role';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 18 ▶use Any::Moose 'X::AttributeHelpers';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 18 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 18 ▶use FormValidator::Nested::Profile;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 18 ▶use Hash::Merge;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 my $behavior = {
9 SCALAR => {
10 2 ▶ SCALAR => sub { $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
11 0 ▶ ARRAY => sub { [ @{$_[1]} ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
12 0 ▶ HASH => sub { $_[1] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
13 },
14 ARRAY => {
15 0 ▶ SCALAR => sub { $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 2 ▶ ARRAY => sub { [ @{$_[1]} ] },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 0 ▶ HASH => sub { $_[1] }
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 },
19 HASH => {
20 0 ▶ SCALAR => sub { $_[1] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
21 0 ▶ ARRAY => sub { [ @{$_[1]} ] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 8 ▶ HASH => sub { Hash::Merge::_merge_hashes( $_[0], $_[1] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
23 },
24 18 };
25 18 Hash::Merge::specify_behavior($behavior);
26  
27 18 requires 'get_profile_data';
28  
29 has '_profiles' => (
30 metaclass => 'Collection::Hash',
31 is => 'rw',
32 isa => 'HashRef[FormValidator::Nested::Profile]',
33 17 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 18 provides => {
35 set => '_set_profile',
36 get => '_get_profile',
37 exists => '_exists_profile',
38 },
39 );
40 18 has 'profile_keys' => (
41 metaclass => 'Collection::Array',
42 is => 'rw',
43 isa => 'ArrayRef[Str]',
44 lazy_build => 1,
45 provides => {
46 elements => 'get_profile_keys',
47 push => 'push_profile_keys',
48 },
49 );
50 18 has 'init_read_all_profile' => (
51 is => 'ro',
52 isa => 'Bool',
53 default => 0,
54 );
55 18 has 'visitor' => (
56 is => 'ro',
57 isa => 'Data::Visitor::Callback',
58 );
59 18 has 'filter' => (
60 is => 'ro',
61 isa => 'CodeRef',
62 );
63  
64 17 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
65 17 my $self = shift;
66  
67 17 ▶ if ( $self->init_read_all_profile ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->init_read_all_profile) 2 15 17
68 2 $self->read_all_profile;
69 }
70 }
71  
72  
73 2 ▶sub read_all_profile {
Subroutine read_all_profile: called CC=2 SCAR=6.9
Pod undocumented
74 2 my $self = shift;
75  
76 2 foreach my $profile_key ( $self->get_profile_keys ) {
77 22 $self->get_profile($profile_key);
78 }
79 }
80  
81 199 ▶sub get_profile {
Subroutine get_profile: called CC=6 SCAR=18.0
Pod undocumented
82 199 my $self = shift;
83 199 my $key = shift;
84  
85 199 ▶ if ( !$self->_exists_profile($key) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_exists_profile($key)) 44 155 199
86 44 my $data = $self->get_profile_data($key);
87 44 ▶ if ( !$data ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 2 42 44
88 2 return 0;
89 }
90 42 ▶ if ( $self->visitor ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->visitor) 0 42 42
91 0 $data = $self->visitor->visit($data);
92 }
93 42 ▶ if ( $self->filter ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filter) 21 21 42
94 21 $self->filter->($data);
95 }
96  
97 42 ▶ if ( $data->{extends} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"extends"}) 4 38 42
98 4 $data = Hash::Merge::merge($self->get_profile($data->{extends})->data, $data);
99 }
100  
101 42 $self->_set_profile($key => FormValidator::Nested::Profile->new({
102 provider => $self,
103 key => $key,
104 data => $data,
105 }));
106 }
107  
108 196 return $self->_get_profile($key);
109 }
110  
111 18 1;
112  
« Nested/Validator/DateTime.pm ↑ Summary Nested/Validator/Bool.pm »