blib/lib/CCCP/AttributeInspector.pm

filter: Statementstmt 17.4% 15 / 86 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 36.3% 4 / 11 Podpod 100% 4 / 4 totaltotal 13.2% 23 / 173 CC 35 SCAR 47.5
CC
35
Cov
10%
att_methods
272.0
get_attributes
56.0
all_methods
42.0
CRAP 115.4
↑ Summary
1 package CCCP::AttributeInspector;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.01';
7  
8 # singleton
9 1 my $pm = undef;
10  
11 0 ▶sub __pm_new {
Subroutine __pm_new: not called CC=2 SCAR=17.9
12 0 ▶ $pm ? $pm : ($pm = bless({},__PACKAGE__));
Branch: 1 branch
BranchTrueFalseTotal
$pm ? : 0 0 0
13 }
14  
15 0 ▶sub __internal_resolv {
Subroutine __internal_resolv: not called CC=3 SCAR=19.2
16 0 my ($obj,$class) = @_;
17
18 0 ▶ return if exists $obj->{'__internal_resolv'}->{$class};
Branch: 1 branch
BranchTrueFalseTotal
if exists $obj->{"__internal_resolv"}{$class} 0 0 0
19
20 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 $obj->{'__all_methods'}->{$class} = [grep {defined &{"${class}::$_"}} keys %{sprintf('%s::',$class)}];
22 map {
23 0 ▶ if (exists $obj->{$class}->{\&{"${class}::$_"}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $obj->{$class}{\&{"${class}::$_";}}) 0 0 0
24 0 $obj->{$class}->{$_} = delete $obj->{$class}->{\&{"${class}::$_"}};
25 }
26 0 } @{$obj->{'__all_methods'}->{$class}};
27 1 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
28
29 0 $obj->{'__internal_resolv'}->{$class}++;
30
31 0 return;
32 }
33  
34 0 ▶sub all_methods {
Subroutine all_methods: not called CC=6 SCAR=37.4
Pod documented
35 0 my ($class) = @_;
36
37 0 ▶ return unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 0 0
38 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
39
40 0 my $obj = __PACKAGE__->__pm_new();
41
42 0 ▶ return wantarray() ? () : [] unless exists $obj->{$class};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $obj->{$class} 0 0 0
wantarray ? : 0 0 0
43
44 0 $obj->__internal_resolv($class);
45
46 0 ▶ return wantarray() ? @{$obj->{'__all_methods'}->{$class}} : $obj->{'__all_methods'}->{$class};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
47 }
48  
49 0 ▶sub att_methods {
Subroutine att_methods: not called CC=16 SCAR=56.1
Pod documented
50 0 my ($class,$att_list) = @_;
51
52 0 ▶ return unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 0 0 0
53 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
54
55 0 my $obj = __PACKAGE__->__pm_new();
56
57 0 ▶ return wantarray() ? () : [] unless exists $obj->{$class};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $obj->{$class} 0 0 0
wantarray ? : 0 0 0
58
59 0 $obj->__internal_resolv($class);
60
61 0 ▶ unless ($att_list) {
Branch: 3 branches
BranchTrueFalseTotal
if ($att_list) { } 0 0 0
if (do { ref $att_list eq 'HASH' }) { } 0 0 0
elsif (ref $att_list eq 'ARRAY') { } 0 0 0
62 0 ▶ return wantarray() ? keys %{$obj->{$class}} : [keys %{$obj->{$class}}];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
63 } elsif (ref $att_list eq 'HASH') {
64 my @ret = grep {
65 0 my $meth = $_;
66 0 my $good = 1;
67 0 foreach (keys %$att_list) {
68 0 ▶ unless (exists $obj->{$class}->{$meth}->{$_} and $obj->{$class}->{$meth}->{$_} eq $att_list->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $obj->{$class}{$meth}{$_} and $obj->{$class}{$meth}{$_} eq $att_list->{$_}) 0 0 0
Condition0%0/3
exists $obj->{$class}{$meth}{$_} and $obj->{$class}{$meth}{$_} eq $att_list->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $obj->{$class}{$meth}{$_} and $obj->{$class}{$meth}{$_} eq $att_list->{$_}
exists $obj->{$class}{$meth}{$_} $obj->{$class}{$meth}{$_} eq $att_list->{$_}
Truth table0%0/3
A and B
A= exists $obj->{$class}{$meth}{$_}B= $obj->{$class}{$meth}{$_} eq $att_list->{$_}
ABresult
0X0
100
111
69 0 $good = 0;
70 0 last;
71 };
72 };
73 0 $good;
74 0 } keys %{$obj->{$class}};
75 0 ▶ return wantarray() ? @ret : [@ret];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
76 } elsif (ref $att_list eq 'ARRAY') {
77 my @ret = grep {
78 0 my $meth = $_;
79 0 my $good = 1;
80 0 foreach (@$att_list) {
81 0 ▶ unless (exists $obj->{$class}->{$meth}->{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $obj->{$class}{$meth}{$_}) 0 0 0
82 0 $good = 0;
83 0 last;
84 };
85 };
86 0 $good;
87 0 } keys %{$obj->{$class}};
88 0 ▶ return wantarray() ? @ret : [@ret];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
89 };
90 }
91  
92 0 ▶sub get_attributes {
Subroutine get_attributes: not called CC=7 SCAR=40.3
Pod documented
93 0 my ($class,$method) = @_;
94
95 0 ▶ return {} unless ($class and $method and not ref $method);
Branch: 1 branch
BranchTrueFalseTotal
unless $class and $method and not ref $method 0 0 0
Condition0%0/6
$class and $method and not ref $method
!ll&&!rl&&r
000
$class and $method
!ll&&!rl&&r
000
MC/DC0%0/3
$class and $method and not ref $method
$class $method not ref $method
Truth table0%0/4
A and B and not(C)
A= $classB= $methodC= not ref $method
ABCresult
0XX0
10X0
1100
1111
96 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
97
98 0 my $obj = __PACKAGE__->__pm_new();
99 0 ▶ return {} unless (exists $obj->{$class});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $obj->{$class} 0 0 0
100
101 0 $obj->__internal_resolv($class);
102
103 0 ▶ return exists $obj->{$class}->{$method} ? $obj->{$class}->{$method} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $obj->{$class}{$method} ? : 0 0 0
104 }
105  
106 0 ▶sub packages {
Subroutine packages: not called CC=2 SCAR=17.9
Pod documented
107 0 my $obj = __PACKAGE__->__pm_new();
108 0 ▶ return wantarray() ? keys %$obj : [keys %$obj];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
109 }
110  
111 0 ▶sub MODIFY_CODE_ATTRIBUTES {
Subroutine MODIFY_CODE_ATTRIBUTES: not called CC=5 SCAR=34.0
112 0 my ($class, $code, @attrs) = @_;
113 0 ▶ return () unless @attrs;
Branch: 1 branch
BranchTrueFalseTotal
unless @attrs 0 0 0
114
115 0 my $obj = __PACKAGE__->__pm_new();
116
117 0 foreach (@attrs) {
118 0 /(\w+)\((['"]?)/;
119 0 ▶ my $quote = $2 || '';
Condition0%0/2
$2 || ''
l!l
00
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
Aresult
11
00
120 0 my ($attr_name,$undef,$attr_value) = $_ =~ /(\w+)(\($quote(.*)$quote\))?/;
121 0 ▶ $obj->{$class}->{$code}->{$attr_name} = $attr_value || '';
Condition0%0/2
$attr_value || ''
l!l
00
MC/DC0%0/1
$attr_value || ''
$attr_value
Truth table0%0/2
A
A= $attr_value
Aresult
11
00
122 };
123
124 0 return ();
125 }
126  
127  
128 1 1;
129 __END__
↑ Summary