File Coverage

lib/Crypt/RSA/Errorhandler.pm
Criterion Covered Total %
statement 15 18 83.3
branch 6 8 75.0
condition n/a
subroutine 4 5 80.0
pod 4 4 100.0
total 29 35 82.8


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -sw
2             ##
3             ## Crypt::RSA::Errorhandler -- Base class that provides error
4             ## handling functionality.
5             ##
6             ## Copyright (c) 2001, Vipul Ved Prakash. All rights reserved.
7             ## This code is free software; you can redistribute it and/or modify
8             ## it under the same terms as Perl itself.
9             ##
10             ## $Id: Errorhandler.pm,v 1.5 2001/06/22 23:27:35 vipul Exp $
11              
12             package Crypt::RSA::Errorhandler;
13 6     6   5135 use strict;
  6         13  
  6         1885  
14              
15             sub new {
16 1     1 1 39 bless {}, shift
17             }
18              
19              
20             sub error {
21 3     3 1 28 my ($self, $errstr, @towipe) = @_;
22 3         19 $$self{errstr} = "$errstr\n";
23 3         5 for (@towipe) {
24 3         3 my $var = $_;
25 3 50       15 if (ref($var) =~ /Crypt::RSA/) {
    100          
    100          
    50          
26 0         0 $var->DESTROY();
27             } elsif (ref($var) eq "SCALAR") {
28 1         4 $$var = "";
29             } elsif (ref($var) eq "ARRAY") {
30 1         4 @$var = ();
31             } elsif (ref($var) eq "HASH") {
32 1         4 %$var = ();
33             }
34             }
35 3         7 return;
36             }
37              
38              
39             sub errstr {
40 3     3 1 10 my $self = shift;
41 3         8 return $$self{errstr};
42             }
43              
44             sub errstrrst {
45 0     0 1   my $self = shift;
46 0           $$self{errstr} = "";
47             }
48              
49             1;
50              
51              
52             =head1 NAME
53              
54             Crypt::RSA::Errorhandler - Error handling mechanism for Crypt::RSA.
55              
56             =head1 SYNOPSIS
57              
58             package Foo;
59              
60             use Crypt::RSA::Errorhandler;
61             @ISA = qw(Crypt::RSA::Errorhandler);
62            
63             sub alive {
64             ..
65             ..
66             return
67             $self->error ("Awake, awake! Ring the alarum bell. \
68             Murther and treason!", $dagger)
69             if $self->murdered($king);
70             }
71              
72              
73             package main;
74              
75             use Foo;
76             my $foo = new Foo;
77             $foo->alive($king) or print $foo->errstr();
78             # prints "Awake, awake! ... "
79              
80             =head1 DESCRIPTION
81              
82             Crypt::RSA::Errorhandler encapsulates the error handling mechanism used
83             by the modules in Crypt::RSA bundle. Crypt::RSA::Errorhandler doesn't
84             have a constructor and is meant to be inherited. The derived modules use
85             its two methods, error() and errstr(), to communicate error messages to
86             the caller.
87              
88             When a method of the derived module fails, it calls $self->error() and
89             returns undef to the caller. The error message passed to error() is made
90             available to the caller through the errstr() accessor. error() also
91             accepts a list of sensitive data that it wipes out (undef'es) before
92             returning.
93              
94             The caller should B call errstr() to check for errors. errstr()
95             should be called only when a method indicates (usually through an undef
96             return value) that an error has occured. This is because errstr() is
97             never overwritten and will always contain a value after the occurance of
98             first error.
99              
100             =head1 METHODS
101              
102             =over 4
103              
104             =item B
105              
106             Barebones constructor.
107              
108             =item B
109              
110             The first argument to error() is $message which is placed in $self-
111             >{errstr} and the remaining arguments are interpretted as
112             variables containing sensitive data that are wiped out from the
113             memory. error() always returns undef.
114              
115             =item B
116              
117             errstr() is an accessor method for $self->{errstr}.
118              
119             =item B
120              
121             This method sets $self->{errstr} to an empty string.
122              
123             =back
124              
125             =head1 AUTHOR
126              
127             Vipul Ved Prakash, Email@vipul.netE
128              
129             =head1 SEE ALSO
130              
131             Crypt::RSA(3)
132              
133             =cut
134              
135