home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Errorhandler.pm < prev    next >
Encoding:
Perl POD Document  |  2001-06-22  |  2.9 KB  |  128 lines

  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. use strict;
  14.  
  15. sub new { 
  16.     bless {}, shift
  17. }
  18.  
  19.  
  20. sub error { 
  21.     my ($self, $errstr, @towipe) = @_;
  22.     $$self{errstr} = "$errstr\n";
  23.     for (@towipe) { 
  24.         my $var = $_;
  25.         if (ref($var) =~ /Crypt::RSA/) { 
  26.             $var->DESTROY();
  27.         } elsif (ref($var) eq "SCALAR") { 
  28.             $$var = ""; 
  29.         } elsif (ref($var) eq "ARRAY") { 
  30.             @$var = ();
  31.         } elsif (ref($var) eq "HASH") { 
  32.             %$var = ();
  33.         }
  34.     }
  35.     return;    
  36.  
  37.  
  38. sub errstr { 
  39.     my $self = shift;
  40.     return $$self{errstr};
  41. }
  42.  
  43. sub errstrrst { 
  44.     my $self = shift;
  45.     $$self{errstr} = "";
  46. }
  47.  
  48. 1;
  49.  
  50.  
  51. =head1 NAME
  52.  
  53. Crypt::RSA::Errorhandler - Error handling mechanism for Crypt::RSA.
  54.  
  55. =head1 SYNOPSIS
  56.  
  57.     package Foo;
  58.  
  59.     use Crypt::RSA::Errorhandler;
  60.     @ISA = qw(Crypt::RSA::Errorhandler);
  61.     
  62.     sub alive { 
  63.         ..
  64.         ..
  65.         return 
  66.         $self->error ("Awake, awake! Ring the alarum bell. \
  67.                        Murther and treason!", $dagger) 
  68.             if $self->murdered($king);
  69.     }
  70.  
  71.  
  72.     package main; 
  73.  
  74.     use Foo;
  75.     my $foo = new Foo;
  76.     $foo->alive($king) or print $foo->errstr(); 
  77.         # prints "Awake, awake! ... "
  78.  
  79. =head1 DESCRIPTION 
  80.  
  81. Crypt::RSA::Errorhandler encapsulates the error handling mechanism used
  82. by the modules in Crypt::RSA bundle. Crypt::RSA::Errorhandler doesn't
  83. have a constructor and is meant to be inherited. The derived modules use
  84. its two methods, error() and errstr(), to communicate error messages to
  85. the caller.
  86.  
  87. When a method of the derived module fails, it calls $self->error() and
  88. returns undef to the caller. The error message passed to error() is made
  89. available to the caller through the errstr() accessor. error() also
  90. accepts a list of sensitive data that it wipes out (undef'es) before
  91. returning.
  92.  
  93. The caller should B<never> call errstr() to check for errors. errstr()
  94. should be called only when a method indicates (usually through an undef
  95. return value) that an error has occured. This is because errstr() is
  96. never overwritten and will always contain a value after the occurance of
  97. first error.
  98.  
  99. =head1 METHODS
  100.  
  101. =over 4
  102.  
  103. =item B<error($mesage, ($wipeme, $wipemetoo))>
  104.  
  105. The first argument to error() is $message which is placed in
  106. $self->{errstr} and the remaining arguments are interpretted as variables
  107. containing sensitive data that are wiped out from the memory. error()
  108. always returns undef.
  109.  
  110. =item B<errstr()> 
  111.  
  112. errstr() is an accessor method for $self->{errstr}.
  113.  
  114. =back
  115.  
  116. =head1 AUTHOR
  117.  
  118. Vipul Ved Prakash, E<lt>mail@vipul.netE<gt>
  119.  
  120. =head1 SEE ALSO 
  121.  
  122. Crypt::RSA(3)
  123.  
  124. =cut
  125.  
  126.  
  127.