Subject: | adding a option to die in case of error |
Hello Steffen,
could you maybe apply attached patch? It adds a option 'on_fail' to the
constructor that changes the error handling of all functions that would
otherwise return undef and set $@ if set to "die". It doesn't change the
default behaviour of the module and would ease the integration with
modules that expects to die in case of any error.
Best wishes, Mario
Subject: | on_fail_die.diff |
--- /home/dom/opt/lib/perl5/share/perl/5.8.8/Net/ManageSieve.pm.orig 2009-07-29 08:53:15.005708337 +0200
+++ /home/dom/opt/lib/perl5/share/perl/5.8.8/Net/ManageSieve.pm 2009-07-29 09:08:48.370625808 +0200
@@ -114,7 +114,11 @@
one of C<require> to fail, if TLS negotiation fails, or C<auto>,
C<on> or C<yes>, if TLS is to attempt, but a failure is ignored.
-I<Note>: All options are passed through to L<IO::Socket::INET>.
+I<Note>: All of the above options are passed through to L<IO::Socket::INET>.
+
+B<on_fail> - Changes the error handling of all functions that would
+otherwise return undef and set C<$@> if set to "die". They will now
+croak whenever an error is detected.
Example:
@@ -183,6 +187,7 @@
$self->{_last_error} = '';
$self->{_last_command} = '';
$self->{_debug} = 1 if $arg{Debug} || $arg{debug};
+ $self->{_on_fail} = delete $arg{on_fail};
foreach my $h (@{ref($host) ? $host : [ $host ]}) {
$arg{PeerAddr} = $h;
@@ -230,10 +235,11 @@
=head1 METHODS
Unless otherwise stated all methods return either a I<true> or I<false>
-value, with I<true> meaning that the operation was a success. When a method
-states that it returns a value, failure will be returned as I<undef> or an
-empty list. The error is specified in C<$@> and can be returned with the
-L</error> method.
+value, with I<true> meaning that the operation was a success. When
+a method states that it returns a value, failure will be returned as
+I<undef> or an empty list. The error is specified in C<$@> and can be
+returned with the L</error> method. Please see the C<on_fail> parameter of
+new for an alternative error handling scheme.
=over 4
@@ -692,6 +698,10 @@
sub _set_error {
my ($self, $err, $Ad) = @_;
+ if ($self->{_on_fail} eq 'die') {
+ Carp::croak $err;
+ }
+
if($err) {
dbgPrint('ERROR:', $err) if $self->{_debug};
$self->{_last_error} = $err;