Data::Object::Role::Errable

Errable Role for Perl 5

method: error method: error_reset

package Example;

use Moo;

with 'Data::Object::Role::Errable';

package main;

my $example = Example->new;

# $example->error('Oops!')

Data::Object::Types

Data::Object::Role::Tryable

error: rw, opt, ExceptionObject

This package provides a mechanism for handling errors (exceptions). It's a more structured approach to being "throwable". The idea is that any object that consumes this role can set an error which automatically throws an exception which if trapped includes the state (object as thrown) in the exception context.

The error method takes an error message (string) or hashref of exception object constructor attributes and throws an "exception". If the exception is trapped the exception object will contain the object as the exception context. The original object will also have the exception set as the error attribute. The error attribute can be cleared using the error_reset method.

error(ExceptionObject $exception | HashRef $options | Str $message) : ExceptionObject

=example-1 error

package main;

my $example = Example->new;

$example->error('Oops!');

# throws exception

=example-2 error

package main;

my $example = Example->new;

$example->error({ message => 'Oops!'});

# throws exception

=example-3 error

package main;

my $example = Example->new;
my $exception = Data::Object::Exception->new('Oops!');

$example->error($exception);

# throws exception

The error_reset method clears any exception object set on the object.

error_reset() : Any

=example-1 error_reset

package main;

my $example = Example->new;

eval { $example->error('Oops!') };

$example->error_reset

12 POD Errors

The following errors were encountered while parsing the POD:

Around line 10:

Unknown directive: =name

Around line 16:

Unknown directive: =abstract

Around line 22:

Unknown directive: =includes

Around line 29:

Unknown directive: =synopsis

Around line 45:

Unknown directive: =libraries

Around line 51:

Unknown directive: =integrates

Around line 57:

Unknown directive: =attributes

Around line 63:

Unknown directive: =description

Around line 73:

Unknown directive: =method

Around line 82:

Unknown directive: =signature

Around line 119:

Unknown directive: =method

Around line 123:

Unknown directive: =signature