Re: WWW::HTTP
Andreas Kpnig (koen1820@otto.ww.tu-berlin.de)
Wed, 15 Mar 95 11:52:08 +0100
> Any ideas how to solve those?
With multiple inheritance Tim designed in the MakeMaker module a
simple way to let the user specify his own subroutines. Might be
sensible to errorhandlers in general:
Here is your module:
require Carp;
package HTTP::ErrorHandler;
sub confess { shift; die Carp::longmess(@_); }
sub croak { shift; die Carp::shortmess(@_); }
sub carp { shift; warn Carp::shortmess(@_); }
package HTTP;
@ISA=qw(MY::ErrorHandler HTTP::ErrorHandler);
sub request {
my($self, $method, $url, $content, $headers, $timeout) = @_;
warn "DEBUG: request(@_)";
# ... do something
$self->carp("Dont't want to do this...");
$self->croak("Couldn't do something...");
}
__END__
With this design the user may specify his own subroutines for error
handling like so:
package main;
sub MY::ErrorHandler::croak {
warn join(":",@_);
warn "I'm in my own Errorhandler";
}
HTTP->request(qw(foo bar baz));
warn "No Problem";
If he doesn't have his own carp() routine, he gets yours.
Thanks to Tim, who showed me the advantages of multiple inheritance!
andreas