[Israel.pm] how to intercept module calls

Gaal Yahas gaal at forum2.org
Sun Oct 8 11:12:15 PDT 2006


On Sun, Oct 08, 2006 at 06:54:18PM +0200, Tal Kelrich wrote:
> load a module, intercept calls to same to change behavior.
> 
> I'm currently looking at Hook::WrapSub and Aspect for guidance, but any
> spot advice would be helpful

You can get a list of subroutines installed in a package with:

    {
        no strict;
        @subs = grep { defined *{$pkg . "::$_"} } keys %{$pgk . "::"};
    }

A .pm file can declare more than one package, and indeed can install code
in arbitrary other packages as well. I don't know of a good response to
the second of these problems. To battle the first, one solution is to
walk all symbol tables before and after the module load, and compare the
two lists. The way to do that is to install an @INC hook (see perldoc
-f require).

-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list