line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::CanBeA; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
358
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.4'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub subclasses { |
9
|
1
|
|
|
1
|
|
3
|
no strict 'refs'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
208
|
|
10
|
368
|
|
|
368
|
1
|
382
|
my($superclass, $namespace) = @_; |
11
|
368
|
50
|
|
|
|
420
|
die("Need to specify superclass when looking for subclasses\n") |
12
|
|
|
|
|
|
|
unless($superclass); |
13
|
368
|
100
|
|
|
|
339
|
$namespace = (($namespace) ? $namespace : 'main').'::'; |
14
|
368
|
|
|
|
|
311
|
(my $parent = $namespace)=~ s/^main::$//; |
15
|
368
|
|
|
|
|
281
|
my @children = (); |
16
|
368
|
|
|
|
|
206
|
foreach my $child ( |
17
|
366
|
|
|
|
|
452
|
map { s/::$//; $_ } |
|
366
|
|
|
|
|
342
|
|
18
|
7144
|
50
|
66
|
|
|
52114
|
grep { $_ ne 'SUPER::' && $_ ne '::' && $_ ne 'main::' && $_ ne '0::' && !/^::/ && /::$/ } |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
19
|
368
|
|
|
|
|
1874
|
keys %{$namespace} |
20
|
|
|
|
|
|
|
) { |
21
|
366
|
100
|
|
|
|
1918
|
push @children, $parent.$child if("$parent$child"->isa($superclass)); |
22
|
366
|
|
|
|
|
263
|
push @children, @{subclasses($superclass, $parent.$child)}; |
|
366
|
|
|
|
|
431
|
|
23
|
|
|
|
|
|
|
} |
24
|
368
|
|
|
|
|
794
|
return [grep { $_ ne $superclass } @children]; |
|
17
|
|
|
|
|
29
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 NAME |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Class::CanBeA - figure out what your class can be. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 SYNOPSIS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use Class::CanBeA; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my @subclasses = @{Class::CanBeA::subclasses('My::Class')}; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DETAILS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This package provides just one function, which it does *not* export, so you |
40
|
|
|
|
|
|
|
need to call it by its fully qualified name. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 FUNCTIONS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 subclasses |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Takes a single argument, which should be a class name. It returns a |
47
|
|
|
|
|
|
|
reference to an array of all the classes which are loaded and which are |
48
|
|
|
|
|
|
|
subclasses of the specified superclass. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Internally it recurses and passes other parameters to that function, but you |
51
|
|
|
|
|
|
|
don't need to know that, so I haven't mentioned it. Right? |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 BUGS/LIMITATIONS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
No attempt is made to deal with circular inheritance. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Will only tell you about loaded and defined classes, obviously. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 AUTHOR |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
David Cantrell Edavid@cantrell.org.ukE |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 FEEDBACK |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Please let me know if you find this module useful. If reporting a bug, |
66
|
|
|
|
|
|
|
it's helpful to include a minimal code snippet which I can use in the |
67
|
|
|
|
|
|
|
test suite. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SEE ALSO |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Class::ISA |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 LICENCE |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
You may use, modify, distribute and have fun with this software under the |
76
|
|
|
|
|
|
|
same terms as you can with perl itself. You may even use it as a device |
77
|
|
|
|
|
|
|
for distracting leopards. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
'false'; |