diff options
author | Russ Allbery <rra@stanford.edu> | 2007-08-31 16:55:23 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2007-08-31 16:55:23 +0000 |
commit | 0ce8e1f8cf98c34b1d6990473a33f77fc04cac04 (patch) | |
tree | 3cbe7b4e39bc23b88c38143db1dd088e7623c7d2 /perl/Wallet/ACL | |
parent | d67458b024098556511c7cfdc38a94351ed570d4 (diff) |
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.
Diffstat (limited to 'perl/Wallet/ACL')
-rw-r--r-- | perl/Wallet/ACL/Base.pm | 25 | ||||
-rw-r--r-- | perl/Wallet/ACL/Krb5.pm | 6 |
2 files changed, 22 insertions, 9 deletions
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<C< at \S+ line +\d+\.?>> 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 diff --git a/perl/Wallet/ACL/Krb5.pm b/perl/Wallet/ACL/Krb5.pm index ffe1fc5..eab0c28 100644 --- a/perl/Wallet/ACL/Krb5.pm +++ b/perl/Wallet/ACL/Krb5.pm @@ -34,11 +34,11 @@ $VERSION = '0.01'; sub check { my ($self, $principal, $acl) = @_; unless ($principal) { - $self->{error} = 'no principal specified'; + $self->error ('no principal specified'); return undef; } unless ($acl) { - $self->{error} = 'malformed krb5 ACL'; + $self->error ('malformed krb5 ACL'); return undef; } return ($principal eq $acl) ? 1 : 0; @@ -80,7 +80,7 @@ principal if and only if the principal exactly matches the ACL. =item new() -Creates a new ACL verifier. The database handle is not used. +Creates a new ACL verifier. For this verifier, there is no setup work. =item check(PRINCIPAL, ACL) |