[Israel.pm] how to intercept module calls
Yuval Kogman
nothingmuch at woobling.org
Sun Oct 8 22:03:23 EEST 2006
On Sun, Oct 08, 2006 at 20:12:15 +0200, Gaal Yahas wrote:
> 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 . "::"};
> }
err, that should be &{$pkg . "::$_"} or maybe *{$pkg . "::$_"}{CODE}
> 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.
You can copy the entire symbol table to another hash before and
after loading the module, and then diff it using Data::Compare or
even have a convenient hook called via Hash::Merge.
The relationship between .pms and packages is such that a .pm might
extend an existing one, as well as introduce any number of
arbitrary, possibly unrelated packages as well.
--
Yuval Kogman <nothingmuch at woobling.org>
http://nothingmuch.woobling.org 0xEBD27418
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://perl.org.il/pipermail/perl/attachments/20061008/0286af80/attachment.pgp
More information about the Perl
mailing list