lib/CPAN/lib/CGI/Session/ErrorHandler.pm
changeset 0 414e01d06fd5
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/CPAN/lib/CGI/Session/ErrorHandler.pm	Sat Jan 26 15:50:53 2008 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +package CGI::Session::ErrorHandler;
     1.5 +
     1.6 +# $Id: ErrorHandler.pm 351 2006-11-24 14:16:50Z markstos $
     1.7 +
     1.8 +use strict;
     1.9 +$CGI::Session::ErrorHandler::VERSION = "4.20";
    1.10 +
    1.11 +=pod
    1.12 +
    1.13 +=head1 NAME
    1.14 +
    1.15 +CGI::Session::ErrorHandler - error handling routines for CGI::Session
    1.16 +
    1.17 +=head1 SYNOPSIS
    1.18 +
    1.19 +    require CGI::Session::ErrorHandler
    1.20 +    @ISA = qw( CGI::Session::ErrorHandler );
    1.21 +
    1.22 +    sub some_method {
    1.23 +        my $self = shift;
    1.24 +        unless (  $some_condition ) {
    1.25 +            return $self->set_error("some_method(): \$some_condition isn't met");
    1.26 +        }
    1.27 +    }
    1.28 +
    1.29 +=head1 DESCRIPTION
    1.30 +
    1.31 +CGI::Session::ErrorHandler provides set_error() and errstr() methods for setting and accessing error messages from within CGI::Session's components. This method should be used by driver developers for providing CGI::Session-standard error handling routines for their code
    1.32 +
    1.33 +=head2 METHODS
    1.34 +
    1.35 +=over 4
    1.36 +
    1.37 +=item set_error($message)
    1.38 +
    1.39 +Implicitly defines $pkg_name::errstr and sets its value to $message. Return value is B<always> undef.
    1.40 +
    1.41 +=cut
    1.42 +
    1.43 +sub set_error {
    1.44 +    my $class   = shift;
    1.45 +    my $message = shift;
    1.46 +    $class = ref($class) || $class;
    1.47 +    no strict 'refs';
    1.48 +    ${ "$class\::errstr" } = sprintf($message || "", @_);
    1.49 +    return;
    1.50 +}
    1.51 +
    1.52 +=item errstr()
    1.53 +
    1.54 +Returns whatever value was set by the most recent call to set_error(). If no message as has been set yet, the empty string is returned so the message can still concatenate without a warning. 
    1.55 +
    1.56 +=back
    1.57 +
    1.58 +=cut 
    1.59 +
    1.60 +*error = \&errstr;
    1.61 +sub errstr {
    1.62 +    my $class = shift;
    1.63 +    $class = ref( $class ) || $class;
    1.64 +
    1.65 +    no strict 'refs';
    1.66 +    return ${ "$class\::errstr" } || '';
    1.67 +}
    1.68 +
    1.69 +=head1 LICENSING
    1.70 +
    1.71 +For support and licensing information see L<CGI::Session|CGI::Session>.
    1.72 +
    1.73 +=cut
    1.74 +
    1.75 +1;
    1.76 +