lib/Crypt/RSA/Errorhandler.pm

filter: Statementstmt 100% 19 / 19 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 4 / 4 totaltotal 97.2% 35 / 36 CC 6 SCAR 13.9
CC
6
Cov
96%
error
6.0
BEGIN
1.0
new
1.0
CRAP 4.0
« lib/Crypt/RSA/DataFormat.pm ↑ Summary lib/Crypt/RSA/Debug.pm »
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 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
16 1 bless {}, shift
17 }
18  
19  
20 203 ▶sub error {
Subroutine error: called CC=6 SCAR=17.9
Pod documented
21 203 my ($self, $errstr, @towipe) = @_;
22 203 $$self{errstr} = "$errstr\n";
23 203 for (@towipe) {
24 803 my $var = $_;
25 803 ▶ if (ref($var) =~ /Crypt::RSA/) {
Branch: 4 branches
BranchTrueFalseTotal
if (ref($var) =~ /Crypt::RSA/) { } 200 603 803
elsif (ref $var eq 'SCALAR') { } 401 202 603
elsif (ref $var eq 'ARRAY') { } 1 201 202
elsif (ref $var eq 'HASH') { } 201 0 201
26 200 $var->DESTROY();
27 } elsif (ref($var) eq "SCALAR") {
28 401 $$var = "";
29 } elsif (ref($var) eq "ARRAY") {
30 1 @$var = ();
31 } elsif (ref($var) eq "HASH") {
32 201 %$var = ();
33 }
34 }
35 203 return;
36 }
37  
38  
39 12 ▶sub errstr {
Subroutine errstr: called CC=1 SCAR=0.0
Pod documented
40 12 my $self = shift;
41 12 return $$self{errstr};
42 }
43  
44 339 ▶sub errstrrst {
Subroutine errstrrst: called CC=1 SCAR=0.0
Pod documented
45 339 my $self = shift;
46 339 $$self{errstr} = "";
47 }
48  
49 13 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<never> 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<new()>
105  
106 Barebones constructor.
107  
108 =item B<error($mesage, ($wipeme, $wipemetoo))>
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<errstr()>
116  
117 errstr() is an accessor method for $self->{errstr}.
118  
119 =item B<errstrrst()>
120  
121 This method sets $self->{errstr} to an empty string.
122  
123 =back
124  
125 =head1 AUTHOR
126  
127 Vipul Ved Prakash, E<lt>mail@vipul.netE<gt>
128  
129 =head1 SEE ALSO
130  
131 Crypt::RSA(3)
132  
133 =cut
134  
135  
« lib/Crypt/RSA/DataFormat.pm ↑ Summary lib/Crypt/RSA/Debug.pm »