Well, I am not sure why you would want to do that. If you are trying to capture DBI warnings/errors, you can give the DBI handle an error handler:
$h->{RaiseError} = 1; # Turn all warnings into dies
$h->{HandleError} = sub { set_dberror(join('',@_)) };
Any errors generated by the dbh will be passed to your sub.
If you really want to capture capture all warning for specific modules, you might try:
package TrapWarnings;
my %Modules;
BEGIN { $SIG{__WARN__} = \ &trapWarning; }
sub import {
$Modules{caller} = 1;
}
sub trapWarning {
my $caller = caller 1;
if ($Module{$caller}) {
set_dberror(join('',@_))
} else {
warn @_
}
}
# Example use
package Foo;
use TrapWarnings;
warn "foo";
Well that code is completely untested. The general idea is everytime you import your TrapWarnings package, it adds that package to the list of packages to trap warnings for. When a warn happens, it checks the original caller to see if its package is in the list. If so, it traps it, otherwise, just re-warns it.
This is far from ideal, but with creative use of the Carp module you might get where you want to be.
Ted Young
($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
|