Nested/Profile.pm

filter: Statementstmt 100% 44 / 44 Branchbran 90.0% 9 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 10 / 10 Podpod 50.0% 1 / 2 totaltotal 97.1% 67 / 69 CC 8 SCAR 10.6
CC
8
Cov
98%
validate
5.0
_build_params
4.0
BEGIN
1.0
CRAP 2.9
« Nested/Result.pm ↑ Summary Nested/Validator/DateTime.pm »
1 package FormValidator::Nested::Profile;
2 18 ▶use Any::Moose;
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  
6 18 ▶use FormValidator::Nested::Result;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use FormValidator::Nested::Profile::Param;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 18 ▶use Class::Param;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 18 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 18 has 'provider' => (
14 is => 'ro',
15 isa => 'FormValidator::Nested::ProfileProvider',
16 required => 1,
17 weak_ref => 1,
18 );
19 18 has 'key' => (
20 is => 'ro',
21 isa => 'Str',
22 required => 1,
23 );
24 18 has 'data' => (
25 is => 'ro',
26 isa => 'HashRef',
27 required => 1,
28 );
29 18 has 'params' => (
30 metaclass => 'Collection::Hash',
31 is => 'ro',
32 isa => 'HashRef[FormValidator::Nested::Profile::Param]',
33 lazy_build => 1,
34 provides => {
35 values => 'get_params',
36 get => 'get_param',
37 },
38 );
39 18 __PACKAGE__->meta->make_immutable;
40  
41 42 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod documented
42 42 my $self = shift;
43
44 # paramsの初期化
45 42 $self->params;
46 }
47  
48 42 ▶sub _build_params {
Subroutine _build_params: called CC=4 SCAR=13.9
49 42 my $self = shift;
50 42 my %params = ();
51 42 ▶ while ( my ( $param_key, $param_data ) = each %{$self->data->{params}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->data->{"params"};}) 118 41 159
52 $params{$param_key} = FormValidator::Nested::Profile::Param->new({
53 profile => $self,
54 key => $param_key,
55 name => $param_data->{name} || '',
56 array => $param_data->{array},
57 $param_data->{nested} ? (
58 118 ▶ nested => $self->provider->get_profile($param_data->{nested}),
Branch: 1 branch
BranchTrueFalseTotal
$param_data->{'nested'} ? : 4 114 118
Condition100%2/2
$param_data->{'name'} || ''
l!l
7642
MC/DC100%1/1
$param_data->{'name'} || ''
$param_data->{'name'}
Truth table100%2/2
A
A= $param_data->{'name'}
Aresult
11
00
59 ) : (),
60 data => $param_data,
61 });
62 }
63 41 return \%params;
64 }
65  
66  
67 135 ▶sub validate {
Subroutine validate: called CC=5 SCAR=16.1
Pod undocumented
68 135 my ( $self, $req, $parent_names ) = @_;
69  
70 135 ▶ if ( blessed($req) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($req)) { } 108 27 135
elsif (ref $req eq 'HASH') { } 27 0 27
71 108 ▶ if ( !$req->can('param') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->can("param")) 1 107 108
72 1 croak("req cannot call param method.");
73 }
74 }
75 elsif ( ref $req eq 'HASH' ) {
76 27 $req = Class::Param->new($req);
77 }
78  
79 134 my $result = FormValidator::Nested::Result->new;
80  
81 134 foreach my $param ( $self->get_params ) {
82 551 $result->merge($param->validate($req, $parent_names));
83 }
84  
85 134 return $result;
86 }
87  
88  
89 18 1;
90  
« Nested/Result.pm ↑ Summary Nested/Validator/DateTime.pm »