blib/lib/Aion/Meta/Util.pm

filter: Statementstmt 84.8% 191 / 225 Branchbran 66.6% 96 / 144 Conditioncond 92.8% 13 / 14 MC/DCmcdc 87.5% 7 / 8 Subroutinesub 86.1% 56 / 65 Podpod 100% 60 / 60 totaltotal 81.9% 423 / 516 CC 78 SCAR 13.4
CC
78
Cov
78%
val_to_str
16.6
create_getters
3.9
create_accessors
3.0
CRAP 3.8
« blib/lib/Aion/Meta/Feature.pm ↑ Summary blib/lib/Aion/Type.pm »
1 package Aion::Meta::Util;
2  
3 11 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 11 require overload;
6 11 ▶use Scalar::Util qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 our @EXPORT = our @EXPORT_OK = grep {
10 11 my $x = $Aion::Meta::Util::{$_};
11 !ref $x
12 88 && *{$x}{CODE}
13 132 ▶ && !/^(_|(NaN|import)\z)/n
Condition100%5/5
!ref($x) && *{$x;}{'CODE'} && !/^(_|(NaN|import)\z)/nu
!ll&&!rl&&r
771144
not ref $x and *{$x;}{"CODE"}
!ll
4488
MC/DC100%2/2
!ref($x) && *{$x;}{'CODE'} && !/^(_|(NaN|import)\z)/nu
not ref $x !/^(_|(NaN|import)\z)/nu
Truth table100%3/3
not(A) && not(B)
A= not ref $xB= !/^(_|(NaN|import)\z)/nu
ABresult
0X0
100
111
14 } keys %Aion::Meta::Util::;
15  
16 # Создаёт геттеры
17 37 ▶sub create_getters(@) {
Subroutine create_getters: called CC=3 SCAR=13.6
Pod documented
18 37 my $pkg = caller;
19 eval "package $pkg; sub $_ {
20 die \"$_ is ro\" if \@_ > 1;
21 shift->{$_}
22 0 ▶ } 1" or die for @_;
Subroutine args: not called CC=2 SCAR=8.8
Subroutine as: not called CC=2 SCAR=8.8
Subroutine construct: called CC=2 SCAR=8.8
Subroutine getvar: called CC=2 SCAR=8.8
Subroutine has: called CC=2 SCAR=8.8
Subroutine has: not called CC=2 SCAR=8.8
Subroutine name: called CC=2 SCAR=8.8
Subroutine name: called CC=2 SCAR=8.8
Subroutine name: not called CC=2 SCAR=8.8
Subroutine name: called CC=2 SCAR=8.8
Subroutine name: called CC=2 SCAR=8.8
Subroutine opt: called CC=2 SCAR=8.8
Subroutine opt: not called CC=2 SCAR=8.8
Subroutine order: called CC=2 SCAR=8.8
Subroutine pkg: called CC=2 SCAR=8.8
Subroutine pkg: called CC=2 SCAR=8.8
Subroutine pkg: called CC=2 SCAR=8.8
Subroutine pkg: called CC=2 SCAR=8.8
Subroutine pkg: not called CC=2 SCAR=8.8
Subroutine read: called CC=2 SCAR=8.8
Subroutine referent: not called CC=2 SCAR=8.8
Subroutine ret: called CC=2 SCAR=8.8
Subroutine signature: called CC=2 SCAR=8.8
Subroutine subname: called CC=2 SCAR=8.8
Subroutine wrapsub: not called CC=2 SCAR=8.8
Subroutine write: called CC=2 SCAR=8.8
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 27 branches
BranchTrueFalseTotal
eval qq[package $pkg; sub $_ {\n\t\tdie "$_ is ro" if \@_ > 1;\n\t\tshift->{$_}\n\t} 1] or die 153 0 153
if @_ > 1 0 0 0
if @_ > 1 0 0 0
if @_ > 1 0 89 89
if @_ > 1 0 1 1
if @_ > 1 0 1 1
if @_ > 1 0 0 0
if @_ > 1 1 3 4
if @_ > 1 0 2 2
if @_ > 1 0 0 0
if @_ > 1 0 19 19
if @_ > 1 0 1 1
if @_ > 1 0 2 2
if @_ > 1 0 0 0
if @_ > 1 0 1 1
if @_ > 1 0 2 2
if @_ > 1 0 3 3
if @_ > 1 0 51 51
if @_ > 1 0 2 2
if @_ > 1 0 0 0
if @_ > 1 0 1 1
if @_ > 1 0 0 0
if @_ > 1 0 1 1
if @_ > 1 0 11 11
if @_ > 1 0 4 4
if @_ > 1 0 0 0
if @_ > 1 0 1 1
23 }
24  
25 # Создаёт геттеры/сеттеры
26 20 ▶sub create_accessors(@) {
Subroutine create_accessors: called CC=3 SCAR=11.1
Pod documented
27 20 my $pkg = caller;
28 eval "package $pkg; sub $_ {
29 if(\@_ > 1) { \$_[0]->{$_} = \$_[1]; \$_[0] }
30 else { shift->{$_} }
31 0 ▶ } 1" or die for @_;
Subroutine accessor_name: called CC=2 SCAR=7.0
Subroutine builder: called CC=2 SCAR=7.0
Subroutine cleaner: called CC=2 SCAR=7.0
Subroutine clear: called CC=2 SCAR=7.0
Subroutine clearer_name: called CC=2 SCAR=7.0
Subroutine default: called CC=2 SCAR=7.0
Subroutine excessive: called CC=2 SCAR=7.0
Subroutine get: called CC=2 SCAR=7.0
Subroutine getter: called CC=2 SCAR=7.0
Subroutine has: called CC=2 SCAR=7.0
Subroutine init_arg: called CC=2 SCAR=7.0
Subroutine initer: called CC=2 SCAR=7.0
Subroutine isa: called CC=2 SCAR=7.0
Subroutine lazy: called CC=2 SCAR=7.0
Subroutine make_clearer: called CC=2 SCAR=7.0
Subroutine make_predicate: called CC=2 SCAR=7.0
Subroutine make_reader: called CC=2 SCAR=7.0
Subroutine make_writer: called CC=2 SCAR=7.0
Subroutine message: not called CC=2 SCAR=7.0
Subroutine not_specified: called CC=2 SCAR=7.0
Subroutine predicate_name: called CC=2 SCAR=7.0
Subroutine reader_name: called CC=2 SCAR=7.0
Subroutine release: called CC=2 SCAR=7.0
Subroutine required: called CC=2 SCAR=7.0
Subroutine selfret: called CC=2 SCAR=7.0
Subroutine set: called CC=2 SCAR=7.0
Subroutine setter: called CC=2 SCAR=7.0
Subroutine trigger: called CC=2 SCAR=7.0
Subroutine weaken: called CC=2 SCAR=7.0
Subroutine writer_name: called CC=2 SCAR=7.0
Subroutine age: called CC=2 SCAR=7.0
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 32 branches
BranchTrueFalseTotal
eval "package $pkg; sub $_ {\n\t\tif(\@_ > 1) { \$_[0]->{$_} = \$_[1]; \$_[0] }\n\t\telse { shift->{$_} }\n\t} 1" or die 170 0 170
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 2 1 3
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 3 1 4
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 0 0 0
if (@_ > 1) { } 18 1 19
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 27 1 28
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 0 1 1
if (@_ > 1) { } 1 1 2
if (@_ > 1) { } 1 1 2
32 }
33  
34 # Проверяет, имеет ли подпрограмма тело
35 25 ▶sub subref_is_reachable {
Subroutine subref_is_reachable: called CC=2 SCAR=7.0
Pod documented
36 25 my ($subref) = @_;
37 25 require B;
38 25 my $cv = B::svref_2object($subref);
39 25 ▶ return !(B::class($cv->ROOT) eq 'NULL' && !${ $cv->const_sv });
Condition66%2/3
B::class($cv->ROOT) eq 'NULL' && !${$cv->const_sv;}
!ll&&!rl&&r
14011
MC/DC50%1/2
B::class($cv->ROOT) eq 'NULL' && !${$cv->const_sv;}
B::class($cv->ROOT) eq 'NULL' !${$cv->const_sv;}
Truth table66%2/3
A && not(B)
A= B::class($cv->ROOT) eq 'NULL'B= !${$cv->const_sv;}
ABresult
0X0
100
111
40 }
41  
42 # Символьное представление значения
43 11 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
44 11 MAX_DEPTH => 2,
45 MAX_HASH_SIZE => 6,
46 MAX_ARRAY_SIZE => 6,
47 MAX_SCALAR_LENGTH => 255,
48 11 };
49  
50 sub val_to_str($;$);
51 4548 ▶sub val_to_str($;$) {
Subroutine val_to_str: called CC=16 SCAR=28.1
Pod documented
52 4548 my ($v, $depth) = @_;
53
54 4548 ▶ if (!defined $v) { 'undef' }
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $v) { } 16 4532 4548
elsif (ref $v eq 'ARRAY') { } 5 4527 4532
elsif (ref $v eq 'HASH') { } 9 4518 4527
55 elsif (ref $v eq 'ARRAY') {
56 0 ▶ if($depth > MAX_DEPTH) { '[...]' }
Branch: 1 branch
BranchTrueFalseTotal
if ($depth > 2) { } 0 5 5
57 else {
58 5 $depth++;
59 5 ▶ join '', '[', join(', ', map({ val_to_str($_, $depth) } (
Branch: 2 branches
BranchTrueFalseTotal
@$v > 6 ? : 0 5 5
@$v > 6 ? : 0 5 5
60 @$v > MAX_ARRAY_SIZE ? @$v[0..MAX_ARRAY_SIZE] : @$v
61 )), @$v > MAX_ARRAY_SIZE ? '...' : ()), ']';
62 }
63 }
64 elsif (ref $v eq 'HASH') {
65 0 ▶ if($depth > MAX_DEPTH) { '{...}' }
Branch: 1 branch
BranchTrueFalseTotal
if ($depth > 2) { } 0 9 9
66 else {
67 9 $depth++;
68 join '', '{', join(', ', map({
69 9 ▶ qq{$_ => ${\val_to_str($v->{$_}, $depth)}} } (
Branch: 2 branches
BranchTrueFalseTotal
keys %$v > 6 ? : 7 2 9
keys %$v > 6 ? : 7 2 9
70 keys %$v > MAX_HASH_SIZE
71 ? (sort keys %$v)[0..MAX_HASH_SIZE]
72 : sort keys %$v
73 )), keys %$v > MAX_HASH_SIZE ? '...' : ()), '}';
74 }
75 }
76 else {
77 4518 ▶ my $no_str = ref $v || Scalar::Util::looks_like_number($v);
Condition100%3/3
ref $v || &Scalar::Util::looks_like_number($v)
l!l&&r!l&&!r
3169889460
MC/DC100%2/2
ref $v || &Scalar::Util::looks_like_number($v)
ref $v &Scalar::Util::looks_like_number($v)
Truth table100%3/3
A || B
A= ref $vB= &Scalar::Util::looks_like_number($v)
ABresult
1X1
011
000
78  
79 4518 ▶ if(ref $v eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'Regexp') { } 6 4512 4518
80 6 $v = "$v";
81 6 $v =~ s{^\(\?\^?([a-z]*):(.*)\)$}{qr/$2/$1}si;
82 }
83 else {
84 4512 ▶ $v = overload::Overloaded($v) && !overload::Method($v, '""')
Branch: 1 branch
BranchTrueFalseTotal
overload::Overloaded($v) && !overload::Method($v, '""') ? : 1 4511 4512
Condition100%3/3
overload::Overloaded($v) and not overload::Method($v, "\"\"")
!ll&&!rl&&r
134931621
MC/DC100%2/2
overload::Overloaded($v) and not overload::Method($v, "\"\"")
overload::Overloaded($v) not overload::Method($v, "\"\"")
Truth table100%3/3
A and not(B)
A= overload::Overloaded($v)B= not overload::Method($v, "\"\"")
ABresult
0X0
100
111
85 ? join("#", Scalar::Util::reftype($v), Scalar::Util::refaddr($v))
86 : "$v";
87 }
88 4518 ▶ $v = substr($v, 0, MAX_SCALAR_LENGTH) . '...'
Branch: 1 branch
BranchTrueFalseTotal
if length $v > 255 0 4518 4518
89 if length($v) > MAX_SCALAR_LENGTH;
90 4518 ▶ $no_str ? $v : "'${\ $v =~ s/['\\]/\\$&/gr }'"
Branch: 1 branch
BranchTrueFalseTotal
$no_str ? : 4058 460 4518
91 }
92 }
93  
94 11 1;
95  
96 __END__
« blib/lib/Aion/Meta/Feature.pm ↑ Summary blib/lib/Aion/Type.pm »