line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CCCP::AttributeInspector; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23819
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
122
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# singleton |
9
|
|
|
|
|
|
|
my $pm = undef; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub __pm_new { |
12
|
0
|
0
|
|
0
|
|
|
$pm ? $pm : ($pm = bless({},__PACKAGE__)); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub __internal_resolv { |
16
|
0
|
|
|
0
|
|
|
my ($obj,$class) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
0
|
|
|
|
|
return if exists $obj->{'__internal_resolv'}->{$class}; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
176
|
|
21
|
0
|
|
|
|
|
|
$obj->{'__all_methods'}->{$class} = [grep {defined &{"${class}::$_"}} keys %{sprintf('%s::',$class)}]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
map { |
23
|
0
|
0
|
|
|
|
|
if (exists $obj->{$class}->{\&{"${class}::$_"}}) { |
|
0
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$obj->{$class}->{$_} = delete $obj->{$class}->{\&{"${class}::$_"}}; |
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
|
} @{$obj->{'__all_methods'}->{$class}}; |
27
|
1
|
|
|
1
|
|
6
|
use strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
822
|
|
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$obj->{'__internal_resolv'}->{$class}++; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub all_methods { |
35
|
0
|
|
|
0
|
1
|
|
my ($class) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
return unless $class; |
38
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $obj = __PACKAGE__->__pm_new(); |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
return wantarray() ? () : [] unless exists $obj->{$class}; |
|
|
0
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$obj->__internal_resolv($class); |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
return wantarray() ? @{$obj->{'__all_methods'}->{$class}} : $obj->{'__all_methods'}->{$class}; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub att_methods { |
50
|
0
|
|
|
0
|
1
|
|
my ($class,$att_list) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
return unless $class; |
53
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $obj = __PACKAGE__->__pm_new(); |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
return wantarray() ? () : [] unless exists $obj->{$class}; |
|
|
0
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$obj->__internal_resolv($class); |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
unless ($att_list) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
return wantarray() ? keys %{$obj->{$class}} : [keys %{$obj->{$class}}]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} elsif (ref $att_list eq 'HASH') { |
64
|
0
|
|
|
|
|
|
my @ret = grep { |
65
|
0
|
|
|
|
|
|
my $meth = $_; |
66
|
0
|
|
|
|
|
|
my $good = 1; |
67
|
0
|
|
|
|
|
|
foreach (keys %$att_list) { |
68
|
0
|
0
|
0
|
|
|
|
unless (exists $obj->{$class}->{$meth}->{$_} and $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
|
0
|
|
|
|
|
return wantarray() ? @ret : [@ret]; |
76
|
|
|
|
|
|
|
} elsif (ref $att_list eq 'ARRAY') { |
77
|
0
|
|
|
|
|
|
my @ret = grep { |
78
|
0
|
|
|
|
|
|
my $meth = $_; |
79
|
0
|
|
|
|
|
|
my $good = 1; |
80
|
0
|
|
|
|
|
|
foreach (@$att_list) { |
81
|
0
|
0
|
|
|
|
|
unless (exists $obj->{$class}->{$meth}->{$_}) { |
82
|
0
|
|
|
|
|
|
$good = 0; |
83
|
0
|
|
|
|
|
|
last; |
84
|
|
|
|
|
|
|
}; |
85
|
|
|
|
|
|
|
}; |
86
|
0
|
|
|
|
|
|
$good; |
87
|
0
|
|
|
|
|
|
} keys %{$obj->{$class}}; |
88
|
0
|
0
|
|
|
|
|
return wantarray() ? @ret : [@ret]; |
89
|
|
|
|
|
|
|
}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub get_attributes { |
93
|
0
|
|
|
0
|
1
|
|
my ($class,$method) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
0
|
|
|
|
return {} unless ($class and $method and not ref $method); |
|
|
|
0
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $obj = __PACKAGE__->__pm_new(); |
99
|
0
|
0
|
|
|
|
|
return {} unless (exists $obj->{$class}); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$obj->__internal_resolv($class); |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
return exists $obj->{$class}->{$method} ? $obj->{$class}->{$method} : {}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub packages { |
107
|
0
|
|
|
0
|
1
|
|
my $obj = __PACKAGE__->__pm_new(); |
108
|
0
|
0
|
|
|
|
|
return wantarray() ? keys %$obj : [keys %$obj]; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub MODIFY_CODE_ATTRIBUTES { |
112
|
0
|
|
|
0
|
|
|
my ($class, $code, @attrs) = @_; |
113
|
0
|
0
|
|
|
|
|
return () unless @attrs; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $obj = __PACKAGE__->__pm_new(); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
foreach (@attrs) { |
118
|
0
|
|
|
|
|
|
/(\w+)\((['"]?)/; |
119
|
0
|
|
0
|
|
|
|
my $quote = $2 || ''; |
120
|
0
|
|
|
|
|
|
my ($attr_name,$undef,$attr_value) = $_ =~ /(\w+)(\($quote(.*)$quote\))?/; |
121
|
0
|
|
0
|
|
|
|
$obj->{$class}->{$code}->{$attr_name} = $attr_value || ''; |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return (); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
__END__ |