Joe Schaefer <[EMAIL PROTECTED]> writes:
> That way apps like apreq can subclass APR::Error
> and just provide a strerror() method without
> needing str() also, and the "$@" stringization
> remains uniform.
Here's a different approach that will accomplish the same
thing via can(). The upshot of this is that we don't need
to change the APR::Error::strerror() signature; all
current tests pass with this patch.
Comments?
Index: xs/APR/Error/Error_pm
===================================================================
--- xs/APR/Error/Error_pm (revision 156118)
+++ xs/APR/Error/Error_pm (working copy)
@@ -4,14 +4,13 @@
use APR::Util ();
use overload
- nomethod => \&fatal,
+ fallback => 1,
'bool' => \&str,
'==' => \&num_cmp,
'!=' => \&num_cmp_not,
'0+' => \&num,
'""' => \&str;
-sub fatal { die __PACKAGE__ . ": Can't handle '$_[3]'" }
# normally the object is created on the C side, but if you want to
# create one from Perl, you can. just pass a hash with args:
@@ -31,8 +30,9 @@
# - the filename and line number are needed because perl doesn't
# provide that info when exception objects are involved
sub str {
+ my $strerror = $_[0]->can("strerror");
return sprintf "%s: (%d) %s at %s line %d", $_[0]->{func},
- $_[0]->{rc}, APR::Error::strerror($_[0]->{rc}),
+ $_[0]->{rc}, $strerror->($_[0]->{rc}),
$_[0]->{file}, $_[0]->{line};
}
@@ -49,9 +49,10 @@
# returned), so we fixup it here (doesn't quite work for croak
# caller).
sub cluck {
- if (ref $_[0] eq __PACKAGE__) {
+ if ($_[0]->isa(__PACKAGE__)) {
+ my $strerror = $_[0]->can("strerror");
Carp::cluck("$_[0]->{func}: ($_[0]->{rc}) " .
- APR::Error::strerror($_[0]->{rc}));
+ $strerror->($_[0]->{rc}));
}
else {
&Carp::cluck;
@@ -59,9 +60,10 @@
}
sub confess {
- if (ref $_[0] eq __PACKAGE__) {
+ if ($_[0]->isa(__PACKAGE__)) {
+ my $strerror = $_[0]->can("strerror");
Carp::confess("$_[0]->{func}: ($_[0]->{rc}) " .
- APR::Error::strerror($_[0]->{rc}));
+ $strerror->($_[0]->{rc}));
}
else {
&Carp::confess;
--
Joe Schaefer
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]