Devel::Sub::Which - Name information about sub calls à la L<UNIVERSAL/can> and <which>.



NAME

Devel::Sub::Which - Name information about sub calls à la can in the UNIVERSAL manpage and <which(1)>.


SYNOPSIS

        use Devel::Sub::Which qw/:universal/;
        # elsewhere
        $obj->which("foo"); # returns the name of the sub that
                            # will implement the "foo" method
        Devel::Sub::Which::which($code_ref); # returns the name of the ref


DESCRIPTION

I don't like the perl debugger. I'd rather print debug statements as I go along, mostly saying "i'm going to do so and so", so I know what to look for when stuff breaks.

Often I find myself faced with polymorphism crap flying into my face. With multiple inheritence, delegations, runtime generated classes, method calls on non predeterminate values, and so forth, it sometimes makes sense to do:

        my $method = < blah blah blah >;
        debug("i'm going to call $method on $obj. FYI, it's going to be "
                . $obj->which($method));
        $obj->$method()

In order to figure out exactly which $method was responsible for your error, or whatever. This helps the above debugging style by providing more deterministic reporting.


METHODS

OBJ->which( METHOD )

This method determines which subroutine reference will be executed for METHOD, using the UNIVERSAL::can manpage (or any overriding implementation),


FUNCTIONS

which OBJ METHOD
which CODEREF

The first form has the same effect as OBJ->which(METHOD), and the second form just delegates to ref_to_name.

ref_to_name CODEREF

Return a string with the name of CODEREF. Errors generated by the B manpage are not caught.


EXPORTS

Nothing is exported by default. These parameters will have an effect:

:universal

This causes which to become a method in the UNIVERSAL manpage, so that you can call it on any object.

which
ref_to_name

Exports the said functions.


ACKNOWLEGEMENTS

Yitzchak Scott-Thoennes provided the know-how needed to get the name of a sub reference.


AUTHOR

Yuval Kogman <nothingmuch@woobling.org>


COPYRIGHT & LICENSE

        Copyright (c) 2004 Yuval Kogman. All rights reserved
        This program is free software; you can redistribute
        it and/or modify it under the same terms as Perl itself.


SEE ALSO

the DB manpage, the perldebug manpage, the UNIVERSAL manpage, the B manpage