blib/lib/Aion/Meta/Feature.pm

filter: Statementstmt 65.7% 298 / 453 Branchbran 56.6% 77 / 136 Conditioncond 45.4% 5 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 83.1% 59 / 71 Podpod 47.3% 9 / 19 totaltotal 64.4% 449 / 697 CC 80 SCAR 13.6
CC
80
Cov
63%
mk_property
20.1
compare
12.0
accomulator
3.7
CRAP 3.9
« blib/lib/Aion/Types.pm ↑ Summary blib/lib/Aion/Meta/Util.pm »
1 package Aion::Meta::Feature;
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 Aion::Meta::FeatureConstruct;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use List::Util qw/pairmap/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 Aion::Meta::Util::create_getters(qw/pkg name opt has construct order/);
10 5 Aion::Meta::Util::create_accessors(qw/
11 required excessive isa
12 lazy builder default trigger release cleaner
13 make_reader make_writer make_predicate make_clearer
14 /);
15  
16 # Конструктор
17 57 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod documented
18 57 my ($cls, $pkg, $name, @has) = @_;
19  
20 57 my $meta = $Aion::META{$pkg};
21  
22 bless {
23 pkg => $pkg,
24 name => $name,
25 opt => {@has},
26 has => \@has,
27 construct => Aion::Meta::FeatureConstruct->new($pkg, $name),
28 57 ▶ order => scalar keys %{$meta->{feature}},
Condition33%1/3
ref $cls || $cls
l!l&&r!l&&!r
0570
MC/DC0%0/2
ref $cls || $cls
ref $cls $cls
Truth table33%1/3
A || B
A= ref $clsB= $cls
ABresult
1X1
011
000
29 stash => {},
30 }, ref $cls || $cls;
31 }
32  
33 # Строковое представление фичи
34 2 ▶sub stringify {
Subroutine stringify: called CC=1 SCAR=0.0
Pod documented
35 2 my ($self) = @_;
36 2 ▶ my $has = join ', ', pairmap { "$a => ${\
Subroutine __ANON__: called CC=1 SCAR=0.0
37 2 Aion::Meta::Util::val_to_str($b)
38 2 }" } @{$self->{has}};
39 2 return "has $self->{name} => ($has) of $self->{pkg}";
40 }
41  
42 # Создаёт свойство
43 54 ▶sub mk_property {
Subroutine mk_property: called CC=12 SCAR=30.0
Pod documented
44 54 my ($self) = @_;
45  
46 54 my $meta = $Aion::META{$self->pkg};
47  
48 54 my $ASPECT = $meta->{aspect};
49 54 my $has = $self->{has};
50 54 ▶ for(my $i=0; $i<@$has; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$has) 107 54 161
51 107 my ($aspect, $value) = @$has[$i, $i+1];
52 107 my $aspect_sub = $ASPECT->{$aspect};
53 107 ▶ die "has: not exists aspect `$aspect`!" if !$aspect_sub;
Branch: 1 branch
BranchTrueFalseTotal
unless $aspect_sub 0 107 107
54 107 $aspect_sub->($value, $self, $aspect);
55 }
56
57 54 my $accessor = $self->construct->accessor;
58 0 ▶ eval $accessor;
Subroutine _x: called CC=2 SCAR=8.4
Subroutine a: called CC=2 SCAR=8.4
Subroutine accomulator: called CC=3 SCAR=13.1
Subroutine b: called CC=2 SCAR=8.4
Subroutine counter: called CC=3 SCAR=13.1
Subroutine eon: called CC=2 SCAR=8.4
Subroutine ini: called CC=2 SCAR=8.4
Subroutine key1: called CC=2 SCAR=8.4
Subroutine key2: not called CC=2 SCAR=8.4
Subroutine legs: called CC=2 SCAR=8.4
Subroutine moon: called CC=2 SCAR=8.4
Subroutine moon: not called CC=2 SCAR=8.4
Subroutine name: called CC=2 SCAR=8.4
Subroutine op: called CC=2 SCAR=8.4
Subroutine parent: called CC=2 SCAR=8.4
Subroutine pleroma: called CC=3 SCAR=13.1
Subroutine power: called CC=3 SCAR=13.1
Subroutine ro: called CC=2 SCAR=8.4
Subroutine rw: called CC=2 SCAR=8.4
Subroutine type: called CC=2 SCAR=8.4
Subroutine wo: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=3 SCAR=13.1
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=3 SCAR=13.1
Subroutine x: called CC=3 SCAR=13.1
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: not called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine x: called CC=2 SCAR=8.4
Subroutine y: not called CC=2 SCAR=8.4
Subroutine y: not called CC=2 SCAR=8.4
Subroutine y: called CC=2 SCAR=8.4
Subroutine z: not called CC=2 SCAR=8.4
Subroutine z: called CC=2 SCAR=8.4
Subroutine my_feature: called CC=2 SCAR=8.4
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Branch: 50 branches
BranchTrueFalseTotal
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 1 1
unless (exists $self->{"accomulator"}) 1 0 1
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 1 1
unless (exists $self->{"counter"}) 1 0 1
if (@_ > 1) { } 0 2 2
if (@_ > 1) { } 0 24 24
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 0 0
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 2 2
if (@_ > 1) { } 0 0 0
if (@_ > 1) { } 1 4 5
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 1 6 7
if (@_ > 1) { } 0 99 99
unless (exists $self->{"pleroma"}) 8 91 99
if (@_ > 1) { } 0 3 3
unless (exists $self->{"power"}) 1 5 6
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 0 2 2
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 2 2
if (@_ > 1) { } 0 2 2
if (@_ > 1) { } 0 2 2
if (@_ > 1) { } 0 2 2
unless (exists $self->{"x"}) 1 1 2
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 1 1
unless (exists $self->{"x"}) 1 0 1
if (@_ > 1) { } 1 2 3
exists $self->{'x'} ? : 1 0 1
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 0 0
if (@_ > 1) { } 1 0 1
if (@_ > 1) { } 1 0 1
if (@_ > 1) { } 0 2 2
if (@_ > 1) { } 0 0 0
if (@_ > 1) { } 0 0 0
if (@_ > 1) { } 2 2 4
if (@_ > 1) { } 0 0 0
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 5 5
59 54 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 54 54
60  
61 54 ▶ if($self->{make_reader}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_reader"}) 2 52 54
62 2 my $reader = $self->construct->reader;
63 2 ▶ eval $reader;
Subroutine _get_x: called CC=1 SCAR=0.0
Subroutine _get_my_feature: called CC=1 SCAR=0.0
64 2 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
65 }
66
67 54 ▶ if($self->{make_writer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_writer"}) 2 52 54
68 2 my $writer = $self->construct->writer;
69 2 ▶ eval $writer;
Subroutine _set_x: called CC=1 SCAR=0.0
Subroutine _set_my_feature: not called CC=1 SCAR=0.0
70 2 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
71 }
72
73 54 ▶ if($self->{make_predicate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_predicate"}) 9 45 54
74 9 my $predicate = $self->construct->predicate;
75 0 ▶ eval $predicate;
Subroutine _has_x: called CC=1 SCAR=0.1
Subroutine has_pleroma: not called CC=1 SCAR=0.1
Subroutine has_rw: called CC=1 SCAR=0.1
Subroutine has_wo: called CC=1 SCAR=0.1
Subroutine has_x: called CC=1 SCAR=0.1
Subroutine has_x: called CC=1 SCAR=0.1
Subroutine has_x: called CC=1 SCAR=0.1
Subroutine has_my_feature: not called CC=1 SCAR=0.1
Pod undocumented
76 9 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 9 9
77 }
78
79 54 ▶ if($self->{make_clearer}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"make_clearer"}) 6 48 54
80 6 my $clearer = $self->construct->clearer;
81 0 ▶ eval $clearer;
Subroutine clear_pleroma: not called CC=2 SCAR=7.9
Subroutine clear_rw: called CC=2 SCAR=7.9
Subroutine clear_x: called CC=2 SCAR=7.9
Subroutine clear_x_: called CC=2 SCAR=7.9
Subroutine clear_my_feature: not called CC=2 SCAR=7.9
Pod undocumented
Branch: 5 branches
BranchTrueFalseTotal
if (exists $self->{"pleroma"}) 0 0 0
if (exists $self->{"rw"}) 1 0 1
if (exists $self->{"x"}) 1 0 1
if (exists $self->{"x"}) 1 1 2
if (exists $self->{"my_feature"}) 0 1 1
82 6 ▶ die if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
83 }
84 }
85  
86 # Представление себя в коде
87 83 ▶sub meta {
Subroutine meta: called CC=2 SCAR=7.0
Pod documented
88 83 my ($self) = @_;
89 83 ▶ $self->{meta} //= do {
Condition66%2/3
$self->{"meta"} //= do { () = @$self{"pkg", "name"}; "\$Aion::META{'${cls}'}{feature}{$name}" }
l!l&&r!l&&!r
44390
MC/DC0%0/2
$self->{"meta"} //= do { () = @$self{"pkg", "name"}; "\$Aion::META{'${cls}'}{feature}{$name}" }
$self->{"meta"} do { () = @$self{"pkg", "name"}; "\$Aion::META{'${cls}'}{feature}{$name}" }
Truth table66%2/3
A //= B
A= $self->{"meta"}B= do { () = @$self{"pkg", "name"}; "\$Aion::META{'${cls}'}{feature}{$name}" }
ABresult
1X1
011
000
90 39 my ($cls, $name) = @$self{qw/pkg name/};
91 39 "\$Aion::META{'$cls'}{feature}{$name}"
92 };
93 }
94  
95 # Доступ к сташу со свойствами
96 2 ▶sub stash {
Subroutine stash: called CC=3 SCAR=11.0
Pod documented
97 2 my ($self, $key, $val) = @_;
98  
99 2 ▶ my $stash = $self->{stash}{scalar caller} //= {};
Condition100%2/2
$self->{"stash"}{scalar caller} //= {}
l!l
11
MC/DC100%1/1
$self->{"stash"}{scalar caller} //= {}
$self->{"stash"}{scalar caller}
Truth table100%2/2
A
A= $self->{"stash"}{scalar caller}
Aresult
11
00
100
101 2 ▶ @_ > 2? do { $stash->{$key} = $val; $self }: $stash->{$key};
Branch: 1 branch
BranchTrueFalseTotal
@_ > 2 ? : 1 1 2
102 }
103  
104 # Сравнивает старую фичу с перезагружаемой
105 0 ▶sub compare {
Subroutine compare: not called CC=3 SCAR=24.8
Pod documented
106 0 my ($self, $other) = @_;
107
108 0 ▶ die "Types mismatch: $other->{isa} <=> $self->{isa}" if $self->{isa} && $self->{isa} ne $other->{isa};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"isa"} and $self->{"isa"} ne $other->{"isa"} 0 0 0
Condition0%0/3
$self->{"isa"} and $self->{"isa"} ne $other->{"isa"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"isa"} and $self->{"isa"} ne $other->{"isa"}
$self->{"isa"} $self->{"isa"} ne $other->{"isa"}
Truth table0%0/3
A and B
A= $self->{"isa"}B= $self->{"isa"} ne $other->{"isa"}
ABresult
0X0
100
111
109 }
110  
111 5 1;
112  
113 __END__
« blib/lib/Aion/Types.pm ↑ Summary blib/lib/Aion/Meta/Util.pm »