If CGI implements ->can, you should be able to get to a code reference that does
what you want:
my $old_method;
BEGIN {
$old_method = CGI->can('header');
};
sub CGI::header {
print "Before\n";
$old_method->(@_);
print "After\n";
};
Otherwise, I wouldn't mess around with CGI and its namespace but implement a thin
class that just delegates to CGI:
package MyFakeCGI;
use CGI;
sub new {
my ($class,%options) = @_;
$options{ cgi } ||= CGI->new;
my $self = \%options;
bless $self => $class;
};
sub header {
my $self = shift;
print "Before\n";
$_[0]->{cgi}->header->(@_);
print "After\n";
};
# Delegate everything else to CGI
sub AUTOLOAD {
goto &CGI::AUTOLOAD;
};
# Don't delegate DESTROY
sub DESTROY {};
1;
|