line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::Can; |
2
|
1
|
|
|
1
|
|
18726
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
131
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
1319
|
use Class::ISA; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Devel::Symdump; |
6
|
|
|
|
|
|
|
our $VERSION = 0.01; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Class::Can - inspect a class/method and say what it can do (and why) |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Class::Can; |
15
|
|
|
|
|
|
|
print Dumper { Class::Can->interrogate( 'Class::Can' ) }; |
16
|
|
|
|
|
|
|
__END__ |
17
|
|
|
|
|
|
|
$VAR1 = { |
18
|
|
|
|
|
|
|
'interrogate' => 'Class::Can' |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Class::Can interrogates the object heirarchy of a package to return a |
24
|
|
|
|
|
|
|
hash detailling what methods the class could dispatch (as the key), |
25
|
|
|
|
|
|
|
and the package it found it in (as the value). |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub interrogate { |
30
|
|
|
|
|
|
|
my ($self, $class) = @_; |
31
|
|
|
|
|
|
|
my %can; |
32
|
|
|
|
|
|
|
for my $package (reverse Class::ISA::self_and_super_path( $class )) { |
33
|
|
|
|
|
|
|
my @methods = Devel::Symdump->new( $package )->functions; |
34
|
|
|
|
|
|
|
s{.*::}{} for @methods; |
35
|
|
|
|
|
|
|
@can{ @methods } = ($package) x @methods; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
return %can; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 AUTHOR |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Richard Clamp |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 COPYRIGHT |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Copyright 2004 Richard Clamp. All Rights Reserved. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
51
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SEE ALSO |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Class::ISA, Devel::Symdump |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |