README
1NAME
2 UNIVERSAL::which - tells fully qualified name of the method
3
4VERSION
5 $Id: README,v 0.4 2007/05/15 16:01:20 dankogai Exp dankogai $
6
7SYNOPSIS
8 use UNIVERSAL::which;
9 use Some::Sub::Class; # which inherits lots of modules
10 # ....
11 my $o = Some::Sub::Class->new;
12 # in scalar context
13 my $fqn = $o->which("method");
14 # in list context
15 my ($pkg, $name) = $o->which("method");
16 # as function
17 my $fqn = UNIVERSAL::which('Some::Sub::Class', 'method');
18
19DESCRIPTION
20 UNIVERSAL::which provides only one method, "which".
21
22 As the name suggests, it returns the fully qualified name of a given
23 method. Sometimes you want to know the true origin of a method but
24 inheritance and AUTOLOAD gets in your way. This module does just that.
25
26 t/*.t illustrates how UNIVERSAL::which behaves more in details.
27
28 CAVEAT
29 Consider the code below;
30
31 no warnings 'once';
32 package Foo;
33 my $code = sub { 1 };
34 package Bar;
35 *muge = $code;
36
37 In this case, you get "undef" for "$fq = Bar>which('muge')" while
38 "($pkg, $name) = Bar->which('muge')" is "('Foo', '__ANON__')".
39
40 That way the code snippet works as expeted.
41
42 my $fq = Bar->which('muge'); &$fg if $fg;
43
44 if you get 'Bar::__ANON__' instead, perl will croak on you at the 2nd
45 line.
46
47SEE ALSO
48 perlobj, UNIVERSAL::canAUTOLOAD
49
50AUTHORS
51 Dan Kogai, <dankogai at dan.co.jp> <http://search.cpan.org/~dankogai/>
52
53 Original idea seeded by: TANIGUCHI <http://search.cpan.org/~taniguchi/>
54
55 B::svref_2object trick by: HIO <http://search.cpan.org/~hio/>
56
57 AUTOLOAD case suggested by: DAIBA <http://search.cpan.org/~daiba/>
58
59 Anon. coderef bug noted by: MIYAZAKI <http://search.cpan.org/~miyazaki/>
60
61COPYRIGHT AND LICENSE
62 Copyright (C) 2006-2007 by Dan Kogai
63
64 This library is free software; you can redistribute it and/or modify it
65 under the same terms as Perl itself, either Perl version 5.8.8 or, at
66 your option, any later version of Perl 5 you may have available.
67
68