blib/lib/Aion/Meta/RequiresFeature.pm

filter: Statementstmt 81.6% 40 / 49 Branchbran 38.1% 16 / 42 Conditioncond 6.6% 1 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 53.9% 69 / 128 CC 29 SCAR 51.4
CC
29
Cov
54%
_deep_equal
250.7
compare
4.0
new
2.3
CRAP 170.1
↑ Summary blib/lib/Aion/Type/DNF.pm »
1 package Aion::Meta::RequiresFeature;
2  
3 5 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use Aion::Meta::Util qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use List::Util qw/pairmap/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Scalar::Util qw/looks_like_number reftype blessed refaddr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 Aion::Meta::Util::create_getters(qw/pkg name opt has/);
10  
11 # Конструктор
12 6 ▶sub new {
Subroutine new: called CC=2 SCAR=8.1
Pod documented
13 6 my ($cls, $pkg, $name, @has) = @_;
14 6 ▶ bless {pkg => $pkg, name => $name, opt => {@has}, has => \@has}, ref $cls || $cls;
Condition33%1/3
ref $cls || $cls
l!l&&r!l&&!r
060
MC/DC0%0/2
ref $cls || $cls
ref $cls $cls
Truth table33%1/3
A || B
A= ref $clsB= $cls
ABresult
1X1
011
000
15 }
16  
17 # Строковое представление фичи
18 3 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
19 3 my ($self) = @_;
20 6 ▶ my $has = join ', ', pairmap { "$a => ${\
Subroutine __ANON__: called CC=1 SCAR=0.0
21 6 Aion::Meta::Util::val_to_str($b)
22 3 }" } @{$self->{has}};
23 3 return "req $self->{name} => ($has) of $self->{pkg}";
24 }
25  
26 # Сравнивает с фичей, но только значения которые есть в этой
27 6 ▶sub compare {
Subroutine compare: called CC=4 SCAR=13.9
Pod documented
28 6 my ($self, $feature) = @_;
29  
30 6 ▶ die "Requires ${\$self->stringify}" unless UNIVERSAL::isa($feature, 'Aion::Meta::Feature');
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($feature, "Aion::Meta::Feature") 1 5 6
31  
32 5 for my $key (keys %{$self->{opt}}) {
33 7 my $value = $self->{opt}{$key};
34 7 my $feature_value = $feature->{opt}{$key};
35
36 7 ▶ die "Feature mismatch ($key => ${\
Branch: 1 branch
BranchTrueFalseTotal
unless _deep_equal($value, $feature_value) 1 6 7
37 1 Aion::Meta::Util::val_to_str($value)
38 } != ${\
39 1 Aion::Meta::Util::val_to_str($feature_value)
40 1 }) with ${\$self->stringify}"
41 unless _deep_equal($value, $feature_value);
42 }
43 }
44  
45 # Сравнивает два значения
46 7 ▶sub _deep_equal {
Subroutine _deep_equal: called CC=25 SCAR=55.2
47 7 my ($value, $other_value) = @_;
48  
49 7 ▶ if (blessed $value) {
Branch: 6 branches
BranchTrueFalseTotal
if (builtin::blessed($value)) { } 4 3 7
elsif (&looks_like_number($value)) { } 0 3 3
elsif (builtin::reftype($value) eq 'ARRAY') { } 0 3 3
elsif (builtin::reftype($value) eq 'HASH') { } 0 3 3
elsif (builtin::reftype($value) eq 'SCALAR') { } 0 3 3
elsif (builtin::reftype($value) eq 'CODE') { } 0 3 3
50 4 ▶ return "" unless blessed $other_value;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other_value) 0 4 4
51  
52 4 ▶ if (overload::Method($value, '==')) {
Branch: 2 branches
BranchTrueFalseTotal
if (overload::Method($value, '==')) { } 4 0 4
elsif (overload::Method($value, 'eq')) { } 0 0 0
53 4 ▶ return "" unless $value == $other_value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value == $other_value 1 3 4
54 }
55 elsif (overload::Method($value, 'eq')) {
56 0 ▶ return "" unless $value eq $other_value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value eq $other_value 0 0 0
57 }
58 else {
59 0 ▶ return "" unless refaddr $value == refaddr $other_value;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::refaddr($value) == builtin::refaddr($other_value) 0 0 0
60 }
61 }
62 elsif (looks_like_number($value)) {
63 0 ▶ return "" unless looks_like_number($other_value) && $value == $other_value;
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($other_value) and $value == $other_value 0 0 0
Condition0%0/3
&looks_like_number($other_value) and $value == $other_value
!ll&&!rl&&r
000
MC/DC0%0/2
&looks_like_number($other_value) and $value == $other_value
&looks_like_number($other_value) $value == $other_value
Truth table0%0/3
A and B
A= &looks_like_number($other_value)B= $value == $other_value
ABresult
0X0
100
111
64 }
65 elsif (reftype $value eq 'ARRAY') {
66 0 ▶ for(my $i = 0; $i <= $#$value; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $value->$#*) 0 0 0
67 0 ▶ return "" unless _deep_equal($value->[$i], $other_value->[$i]);
Branch: 1 branch
BranchTrueFalseTotal
unless _deep_equal($value->[$i], $other_value->[$i]) 0 0 0
68 }
69 }
70 elsif (reftype $value eq 'HASH') {
71 0 for my $k (keys %$value) {
72 0 ▶ return "" unless exists $other_value->{$k} && _deep_equal($value->{$k}, $other_value->{$k});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $other_value->{$k} and _deep_equal($value->{$k}, $other_value->{$k}) 0 0 0
Condition0%0/3
exists $other_value->{$k} and _deep_equal($value->{$k}, $other_value->{$k})
!ll&&!rl&&r
000
MC/DC0%0/2
exists $other_value->{$k} and _deep_equal($value->{$k}, $other_value->{$k})
exists $other_value->{$k} _deep_equal($value->{$k}, $other_value->{$k})
Truth table0%0/3
A and B
A= exists $other_value->{$k}B= _deep_equal($value->{$k}, $other_value->{$k})
ABresult
0X0
100
111
73 }
74 }
75 elsif (reftype $value eq 'SCALAR') {
76 0 ▶ return "" unless reftype $other_value eq 'SCALAR' && _deep_equal($$value, $$other_value);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($other_value) eq "SCALAR" and _deep_equal($$value, $$other_value) 0 0 0
Condition0%0/3
builtin::reftype($other_value) eq "SCALAR" and _deep_equal($$value, $$other_value)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::reftype($other_value) eq "SCALAR" and _deep_equal($$value, $$other_value)
builtin::reftype($other_value) eq "SCALAR" _deep_equal($$value, $$other_value)
Truth table0%0/3
A and B
A= builtin::reftype($other_value) eq "SCALAR"B= _deep_equal($$value, $$other_value)
ABresult
0X0
100
111
77 }
78 elsif (reftype $value eq 'CODE') {
79 0 ▶ return "" unless reftype $other_value eq 'CODE' && refaddr $value == refaddr $other_value;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($other_value) eq "CODE" and builtin::refaddr($value) == builtin::refaddr($other_value) 0 0 0
Condition0%0/3
builtin::reftype($other_value) eq "CODE" and builtin::refaddr($value) == builtin::refaddr($other_value)
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::reftype($other_value) eq "CODE" and builtin::refaddr($value) == builtin::refaddr($other_value)
builtin::reftype($other_value) eq "CODE" builtin::refaddr($value) == builtin::refaddr($other_value)
Truth table0%0/3
A and B
A= builtin::reftype($other_value) eq "CODE"B= builtin::refaddr($value) == builtin::refaddr($other_value)
ABresult
0X0
100
111
80 }
81 else {
82 3 ▶ return "" if $value ne $other_value;
Branch: 1 branch
BranchTrueFalseTotal
if $value ne $other_value 0 3 3
83 }
84  
85 6 return 1;
86 }
87  
88 5 1;
89  
90 __END__
↑ Summary blib/lib/Aion/Type/DNF.pm »