| 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
MC/DC0%0/2
ref $cls || $cls
ref $cls
$cls
Truth table33%1/3
A || B
A= ref $clsB= $cls
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | return "" unless blessed $other_value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | if (overload::Method($value, '==')) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 53 | 4 | ▶ | return "" unless $value == $other_value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||
| 55 | elsif (overload::Method($value, 'eq')) { | ||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return "" unless $value eq $other_value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return "" unless refaddr $value == refaddr $other_value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||
| 62 | elsif (looks_like_number($value)) { | ||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return "" unless looks_like_number($other_value) && $value == $other_value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&looks_like_number($other_value) and $value == $other_value
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
| |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||
| 65 | elsif (reftype $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | for(my $i = 0; $i <= $#$value; $i++) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return "" unless _deep_equal($value->[$i], $other_value->[$i]); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $other_value->{$k} and _deep_equal($value->{$k}, $other_value->{$k})
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})
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/3
builtin::reftype($other_value) eq "SCALAR" and _deep_equal($$value, $$other_value)
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)
| |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||
| 78 | elsif (reftype $value eq 'CODE') { | ||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return "" unless reftype $other_value eq 'CODE' && refaddr $value == refaddr $other_value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::reftype($other_value) eq "CODE" and builtin::refaddr($value) == builtin::refaddr($other_value)
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)
| |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||
| 81 | else { | ||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | return "" if $value ne $other_value; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | 6 | return 1; | |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | 5 | 1; | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||