| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $obj = __PACKAGE__->__pm_new(); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | return wantarray() ? () : [] unless exists $obj->{$class}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $obj->__internal_resolv($class); | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return wantarray() ? @{$obj->{'__all_methods'}->{$class}} : $obj->{'__all_methods'}->{$class}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $obj = __PACKAGE__->__pm_new(); | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return wantarray() ? () : [] unless exists $obj->{$class}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $obj->__internal_resolv($class); | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | unless ($att_list) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return wantarray() ? keys %{$obj->{$class}} : [keys %{$obj->{$class}}]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
exists $obj->{$class}{$meth}{$_} and $obj->{$class}{$meth}{$_} eq $att_list->{$_}
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->{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$class and $method and not ref $method
$class and $method
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
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $class = ref $class if ref $class; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $obj = __PACKAGE__->__pm_new(); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return {} unless (exists $obj->{$class}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $obj->__internal_resolv($class); | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return exists $obj->{$class}->{$method} ? $obj->{$class}->{$method} : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$2 || ''
$2
Truth table0%0/2
A
A= $2
| |||||||||||||||||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$attr_value || ''
$attr_value
Truth table0%0/2
A
A= $attr_value
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||||||||||||||||