my $old_method; BEGIN { $old_method = CGI->can('header'); }; sub CGI::header { print "Before\n"; $old_method->(@_); print "After\n"; }; #### 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;