NAME

XS::ErrorCode - Perl binding for panda::ErrorCode (nested std::error_code)

SYNOPSIS

my $err = SomeFramework->some_method();
if ($err) {
    say $err;
    say $err->value;
    say $err->category->name;
    say $err->message;
}

DESCRIPTION

This binding is intended for use from XS modules that returns errors as panda::ErrorCode objects to perl. It provides them with typemap and Perl interface.

See XS::STL::ErrorCode for more info about error codes.

API

new($error_code, $next_error_code)

Creates nested error code object from XS::STL::ErrorCode and XS::ErrorCode. Normally you should not create these objects from perl.

value()

Returns top error code value (integer)

category()

Returns top error code category as XS::STL::ErrorCategory object

message()

Returns top error message

code()

Returns top error as XS::STL::ErrorCode object

next()

Returns XS::ErrorCode object with next error as top error or undef if it constains a single error.

Example printing all errors in stack:

while ($err) {
    say $err->value;
    say $err->message;
    $err = $err->next;
}

operator bool

Returns true if object contains errors

operator ""

Stringifies to whole stack of errors. Example output:

Connection timed out (110:generic), preceded by:
Permission denied (13:generic)

operator ==, eq

Compares with XS::ErrorCode or XS::STL::ErrorCode or number. Only top error is compared.

my $err = SomeFramework->some_method();
if ($err == SomeFramework::Error::unauthorized) {
    
}
elsif ($err == XS::STL::errc::connection_refused) {
}

AUTHOR

Pronin Oleg <syber@crazypanda.ru>, Crazy Panda LTD

LICENSE

You may distribute this code under the same terms as Perl itself.