diff options
author | Russ Allbery <rra@stanford.edu> | 2010-02-18 16:14:51 -0800 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2010-02-18 16:14:51 -0800 |
commit | 52ee9b9285f04551cfdcbde2b3b6293a706ca982 (patch) | |
tree | e1c6515bbfd41499a8f74f7a1efec0b1a5c34d76 /perl/Wallet/Kadmin.pm | |
parent | ae9db60c9b9601f66b34b564b80bbcfbe41301e1 (diff) |
Lift the error method into Wallet::Kadmin
Take advantage of inheritance by providing the error method in
Wallet::Kadmin rather than separately in both the subclasses.
Diffstat (limited to 'perl/Wallet/Kadmin.pm')
-rw-r--r-- | perl/Wallet/Kadmin.pm | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/perl/Wallet/Kadmin.pm b/perl/Wallet/Kadmin.pm index 65adc83..78b72cd 100644 --- a/perl/Wallet/Kadmin.pm +++ b/perl/Wallet/Kadmin.pm @@ -26,11 +26,6 @@ $VERSION = '0.03'; # Public methods ############################################################################## -# Set a callback to be called for forked kadmin processes. This does nothing -# by default but may be overridden by subclasses that need special behavior -# (such as the current Wallet::Kadmin::MIT module). -sub fork_callback { } - # Create a new kadmin object, by finding the type requested in the wallet # config and passing off to the proper module. Returns the object directly # from the specific Wallet::Kadmin::* module. @@ -53,6 +48,23 @@ sub new { return $kadmin; } +# Set or return the error stashed in the object. +sub error { + 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}; +} + +# Set a callback to be called for forked kadmin processes. This does nothing +# by default but may be overridden by subclasses that need special behavior +# (such as the current Wallet::Kadmin::MIT module). +sub fork_callback { } + 1; __END__ @@ -112,6 +124,19 @@ implementation is not recognized or set, die with an error message. =over 4 +=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. + +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. + =item fork_callback(CALLBACK) If the module has to fork an external process for some reason, such as a |