From 0ce8e1f8cf98c34b1d6990473a33f77fc04cac04 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Fri, 31 Aug 2007 16:55:23 +0000 Subject: Use a better method of setting the internal error that automatically adjusts for trailing newlines and exception detritus, saving duplicate code. Standardize the documentation of the error() method and document using this in child classes of the generic ACL and Object classes. Disable printing of errors during connect in Wallet::Server since we're going to throw our own exception. --- perl/Wallet/ACL/Base.pm | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'perl/Wallet/ACL/Base.pm') diff --git a/perl/Wallet/ACL/Base.pm b/perl/Wallet/ACL/Base.pm index dfc6b60..a03086d 100644 --- a/perl/Wallet/ACL/Base.pm +++ b/perl/Wallet/ACL/Base.pm @@ -41,9 +41,15 @@ sub check { return 0; } -# Return the error stashed in the object. +# Set or return the error stashed in the object. sub error { - my ($self) = @_; + my ($self, @error) = @_; + if (@error) { + my $error = join ('', @error); + chomp $error; + 1 while ($error =~ s/ at \S+ line \d+\.?\z//); + $self->{error} = $error; + } return $self->{error}; } @@ -87,11 +93,18 @@ and blesses an object. This method should always be overridden by child classes. The default implementation just declines all access. -=item error() +=item error([ERROR ...]) + +Returns the error of the last failing operation or undef if no operations +have failed. Callers should call this function to get the error message +after an undef return from any other instance method. -Returns whatever is stored in the error key of the object hash. Child -classes should store error messages in that key when returning undef from -check(). +For the convenience of child classes, this method can also be called with +one or more error strings. If so, those strings are concatenated together, +trailing newlines are removed, any text of the form S> at the end of the message is stripped off, and the result is stored +as the error. Only child classes should call this method with an error +string. =back -- cgit v1.2.3