NestedAttributesConstructor/Trait/Class.pm

filter: Statementstmt 100% 40 / 40 Branchbran 88.8% 16 / 18 Conditioncond 75.0% 18 / 24 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 85.5% 83 / 97 CC 20 SCAR 24.7
CC
20
Cov
90%
_construct
16.5
_construct_hash
3.0
__ANON__
2.0
CRAP 11.8
↑ Summary NestedAttributesConstructor.pm »
1 package MooseX::NestedAttributesConstructor::Trait::Class;
2 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 16 ▶around new_object => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
5 16 my $orig = shift;
6 16 my $self = shift;
7 16 ▶ my $argz = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 16 0 16
8 16 return $self->$orig(_construct($self, $argz));
9 1 };
10  
11 sub _construct
12 19 ▶{
Subroutine _construct: called CC=16 SCAR=28.1
13 19 my ($class, $options) = @_;
14 19 ▶ return $options unless $class->can('meta');
Branch: 1 branch
BranchTrueFalseTotal
unless $class->can("meta") 0 19 19
15  
16 19 ▶ while( my ($name, $val) = each %$options ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$options) 22 18 40
17  
18 # May or may not be a metaclass
19 22 ▶ my $attr = $class->can('get_attribute') ? $class->get_attribute($name) : $class->meta->get_attribute($name);
Branch: 1 branch
BranchTrueFalseTotal
$class->can('get_attribute') ? : 19 3 22
20 22 my $vtype = ref($val);
21  
22 22 ▶ next unless $attr
Branch: 1 branch
BranchTrueFalseTotal
unless $attr and $vtype eq "ARRAY" || $vtype eq "HASH" and not builtin::blessed($val) and $attr->does("NestedAttribute") and $attr->has_type_constraint and $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Class") || $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized") 14 8 22
Condition76%16/21
$attr and $vtype eq "ARRAY" || $vtype eq "HASH" and not builtin::blessed($val) and $attr->does("NestedAttribute") and $attr->has_type_constraint and $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Class") || $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
!ll&&!rl&&r
1408
$attr and $vtype eq "ARRAY" || $vtype eq "HASH" and not builtin::blessed($val) and $attr->does("NestedAttribute") and $attr->has_type_constraint
!ll&&!rl&&r
1408
$attr and $vtype eq "ARRAY" || $vtype eq "HASH" and not builtin::blessed($val) and $attr->does("NestedAttribute")
!ll&&!rl&&r
1318
$attr and $vtype eq "ARRAY" || $vtype eq "HASH" and not builtin::blessed($val)
!ll&&!rl&&r
1309
$attr and $vtype eq "ARRAY" || $vtype eq "HASH"
!ll&&!rl&&r
0139
$vtype eq "ARRAY" or $vtype eq "HASH"
l!l&&r!l&&!r
3613
$attr->type_constraint->isa("Moose::Meta::TypeConstraint::Class") or $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
l!l&&r!l&&!r
530
MC/DC37%3/8
$attr and $vtype eq "ARRAY" || $vtype eq "HASH" and not builtin::blessed($val) and $attr->does("NestedAttribute") and $attr->has_type_constraint and $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Class") || $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
$attr $vtype eq "ARRAY" $vtype eq "HASH" not builtin::blessed($val) $attr->does("NestedAttribute") $attr->has_type_constraint $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Class") $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
Truth table35%5/14
A and B or C and not(D) and E and F and G or H
A= $attrB= $vtype eq "ARRAY"C= $vtype eq "HASH"D= not builtin::blessed($val)E= $attr->does("NestedAttribute")F= $attr->has_type_constraintG= $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Class")H= $attr->type_constraint->isa("Moose::Meta::TypeConstraint::Parameterized")
ABCDEFGHresult
0XXXXXXX0
100XXXXX0
11X0XXXX0
1010XXXX0
11X10XXX0
10110XXX0
11X110XX0
101110XX0
11X111000
101111000
11X1111X1
11X111011
1011111X1
101111011
23 and ($vtype eq 'ARRAY' or $vtype eq 'HASH')
24 and !blessed($val)
25 and $attr->does('NestedAttribute')
26 and $attr->has_type_constraint
27 and ($attr->type_constraint->isa('Moose::Meta::TypeConstraint::Class') or
28 $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized'));
29  
30 8 my $ctype;
31 8 my $param = 1;
32  
33 8 ▶ if($attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { } 3 5 8
34 3 $ctype = $attr->type_constraint->type_parameter->class;
35 }
36 else {
37 5 $ctype = $attr->type_constraint->class;
38 5 $param = 0;
39 }
40  
41 8 ▶ if($vtype eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($vtype eq 'HASH') { } 6 2 8
elsif ($param and ref $val->[0] eq 'HASH') { } 1 1 2
42 6 $val = _construct_hash($ctype, $val, $param);
43 }
44 ▶ elsif($param && ref($val->[0]) eq 'HASH') {
Condition66%2/3
$param and ref $val->[0] eq "HASH"
!ll&&!rl&&r
011
MC/DC50%1/2
$param and ref $val->[0] eq "HASH"
$param ref $val->[0] eq "HASH"
Truth table66%2/3
A and B
A= $paramB= ref $val->[0] eq "HASH"
ABresult
0X0
100
111
45 1 $val = _construct_array($ctype, $val);
46 }
47  
48 7 $options->{$name} = $val;
49 }
50  
51 18 return $options;
52 }
53  
54 sub _construct_array
55 1 ▶{
Subroutine _construct_array: called CC=2 SCAR=6.9
56 1 my ($class, $val) = @_;
57 1 my $collection = [];
58 1 for(@$val) {
59 2 my $options = _construct($class, $_);
60 2 push @$collection, $class->new(%$options);
61 }
62  
63 1 $collection;
64 }
65  
66 sub _construct_hash
67 6 ▶{
Subroutine _construct_hash: called CC=3 SCAR=11.0
68 6 my ($class, $val, $is_param) = @_;
69  
70 6 ▶ if($is_param) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_param) 1 5 6
71 1 my $collection = {};
72 1 for(keys %$val) {
73 1 my $options = _construct($class, $val->{$_});
74 1 $collection->{$_} = $class->new(%$options);
75 }
76  
77 1 return $collection;
78 }
79  
80 5 $class->new(%$val);
81 }
82  
83 1 1;
↑ Summary NestedAttributesConstructor.pm »