CPANPLUS::Error - Error handling for the CPAN++ interface



NAME

CPANPLUS::Error - Error handling for the CPAN++ interface


SYNOPSIS

    use CPANPLUS::Error;
    my $obj = new CPANPLUS::Error(
        error_track   => 1,
        error_level   => 2,
        message_track => 0,
        message_level => 1,
    );
    $obj->trap(  error => 'There was an error!');
    $obj->inform(msg   => 'I did something', quiet=>1);
    my @all_errors = $obj->stack();
    my $last_msg   = $obj->list();
    my $last_two_errors = $obj->flush(2);
    my $all_messages = $obj->forget();
    my $msg_and_err = summarize(all => 1);


DESCRIPTION

CPANPLUS::Error provides a standard method of handling errors for components of the CPAN++ interface.


METHODS

new(error_track => bool, error_level => number, message_track => bool, message_level => bool)

The constructor expects a hash of arguments for the following fields:

error_level
The setting is a number from 0 to 3 which indicates what should happen when an error is reported. Regardless of the setting, error messages will be saved for later access. By default the error level is 1.
      0  no action
      1  Carp ('warn')
      2  Croak ('die')
    > 2  Confess ('die with a stacktrace')

error_track
If enabled, the name of the subroutine in which the error occurred will be appended to each error message. By default it is false.

message_level
This field specifies the handling level for messages. By default the level is 0. If true, messages will be printed when they are reported.

message_track
If true, each message will track the subroutine in which the message occurred. By default it is false.

trap(error => ERROR, quiet => bool )

This method puts the error message on the error stack. The optional 'quiet' argument will override the error_level setting and prevent error actions from being taken. 1 is returned for success in handling the error; 0 is returned otherwise.

inform(msg => WARNING, quiet => bool)

This function behaves like trap() except that it manipulates messages instead of errors. It returns 1 if the message was handled, and 0 if it was not.

stack()

If called in list context, stack() returns the contents of the error stack. If called in scalar context, it returns the most recent error.

list()

In list context, this method returns the message stack. In scalar context it returns the most recent message.

flush([NUMBER])

Flush removes the specified number of errors from the error stack and returns an array reference containing the removed errors. If no argument is specified, the entire stack is emptied.

forget([NUMBER])

This method is like flush() except that it operates on the message stack.

summarize(ARG => BOOL)

This method allows errors and messages to be combined in the order in which they were logged. If no argument is specified, error is assumed. It accepts the following keys:

An array reference containing the results is returned.


AUTHORS

Copyright (c) 2001, 2002 Jos Boumans <kane@cpan.org> and Ann Barcomb <kudra@cpan.org>. All rights reserved.

This documentation Copyright (c) 2002 Ann Barcomb <kudra@cpan.org>.

This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.

 CPANPLUS::Error - Error handling for the CPAN++ interface