| Concurrent-Object documentation | Contained in the Concurrent-Object distribution. |
Concurrent::Errorhandler - Error handling mechanism for Concurrent.
package Foo;
use Concurrent::Errorhandler;
@ISA = qw(Concurrent::Errorhandler);
sub alive {
..
..
return
$self->error ("Awake, awake! Ring the alarum bell. \
Murther and treason!", $dagger)
if $self->murdered($king);
}
package main;
use Foo;
my $foo = new Foo;
$foo->alive($king) or print $foo->errstr();
# prints "Awake, awake! ... "
Concurrent::Errorhandler encapsulates the error handling mechanism used by the modules in Concurrent bundle. Concurrent::Errorhandler doesn't have a constructor and is meant to be inherited. The derived modules use its two methods, error() and errstr(), to communicate error messages to the caller.
When a method of the derived module fails, it calls $self->error() and returns undef to the caller. The error message passed to error() is made available to the caller through the errstr() accessor. error() also accepts a list of sensitive data that it wipes out (undef'es) before returning.
The caller should never call errstr() to check for errors. errstr() should be called only when a method indicates (usually through an undef return value) that an error has occured. This is because errstr() is never overwritten and will always contain a value after the occurance of first error.
The first argument to error() is $message which is placed in $self->{errstr} and the remaining arguments are interpretted as variables containing sensitive data that are wiped out from the memory. error() always returns undef.
errstr() is an accessor method for $self->{errstr}.
Vipul Ved Prakash, <mail@vipul.net>
Concurrent(3)
| Concurrent-Object documentation | Contained in the Concurrent-Object distribution. |
#!/usr/bin/perl -sw ## ## Concurrent::Errorhandler -- Base class that provides error ## handling functionality. ## ## Copyright (c) 2001, Vipul Ved Prakash. All rights reserved. ## This code is free software; you can redistribute it and/or modify ## it under the same terms as Perl itself. ## ## $Id: Errorhandler.pm,v 1.1.1.1 2001/06/10 14:39:39 vipul Exp $ package Concurrent::Errorhandler; use strict; sub new { bless {}, shift } sub error { my ($self, $errstr, @towipe) = @_; $$self{errstr} = "$errstr\n"; for (@towipe) { my $var = $_; if (ref($var) =~ /Concurrent/) { $var->DESTROY(); } elsif (ref($var) eq "SCALAR") { $$var = ""; } elsif (ref($var) eq "ARRAY") { @$var = (); } elsif (ref($var) eq "HASH") { %$var = (); } } return; } sub errstr { my $self = shift; return $$self{errstr}; } 1;