perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Schaefer <joe+gm...@sunstarsys.com>
Subject Re: ACL filesystem incompatibility and potential race condition
Date Fri, 04 Mar 2005 13:17:27 GMT
Joe Schaefer <joe+gmane@sunstarsys.com> 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: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org


Mime
View raw message