Venus::Error

Error Class

Error Class for Perl 5

method: as method: arguments method: callframe method: captured method: explain method: frame method: frames method: is method: of method: render method: throw method: trace

package main;

use Venus::Error;

my $error = Venus::Error->new;

# $error->throw;

This package represents a context-aware error (exception object). The default for error verbosity can be controlled via the VENUS_ERROR_VERBOSE environment variable, e.g. a setting of 0 disables stack traces. The default trace-offset can be controlled via the VENUS_ERROR_TRACE_OFFSET environment variable, e.g. a setting of 0 indicates no offset.

Venus::Kind::Utility

Venus::Role::Explainable Venus::Role::Stashable

name: rw, opt, Str context: rw, opt, Str, '(None)' message: rw, opt, Str, 'Exception!' verbose: rw, opt, Int, 1

The as method returns an error object using the return value(s) of the "as" method specified, which should be defined as "as_${name}", which will be called automatically by this method. If no "as_${name}" method exists, this method will set the "name" attribute to the value provided.

as(string $name) (Venus::Error)

{ since => '1.02', }

=example-1 as

package System::Error;

use Venus::Class;

base 'Venus::Error';

sub as_auth_error {
  my ($self) = @_;

  return $self->do('message', 'auth_error');
}

sub as_role_error {
  my ($self) = @_;

  return $self->do('message', 'role_error');
}

sub is_auth_error {
  my ($self) = @_;

  return $self->message eq 'auth_error';
}

sub is_role_error {
  my ($self) = @_;

  return $self->message eq 'role_error';
}

package main;

my $error = System::Error->new->as('auth_error');

$error->throw;

# Exception! (isa Venus::Error)

The arguments method returns the stashed arguments under "captured", or a specific argument if an index is provided.

arguments(number $index) (any)

{ since => '2.55', }

The callframe method returns the stashed callframe under "captured", or a specific argument if an index is provided.

callframe(number $index) (any)

{ since => '2.55', }

The captured method returns the value stashed as "captured".

captured() (hashref)

{ since => '2.55', }

The explain method returns the error message and is used in stringification operations.

explain() (string)

{ since => '0.01', }

=example-1 explain

# given: synopsis;

my $explain = $error->explain;

# "Exception! in ...

The frame method returns the data from caller on the frames captured, and returns a hashref where the keys map to the keys described by "caller" in perlfunc.

frame(number $index) (hashref)

{ since => '1.11', }

=example-1 frame

# given: synopsis;

my $frame = $error->frame;

# {
#   'bitmask' => '...',
#   'evaltext' => '...',
#   'filename' => '...',
#   'hasargs' => '...',
#   'hinthash' => '...',
#   'hints' => '...',
#   'is_require' => '...',
#   'line' => '...',
#   'package' => '...',
#   'subroutine' => '...',
#   'wantarray' => '...',
# }

The frames method returns the compiled and stashed stack trace data.

frames() (arrayref)

{ since => '0.01', }

=example-1 frames

# given: synopsis;

my $frames = $error->frames;

# [
#   ...
#   [
#     "main",
#     "t/Venus_Error.t",
#     ...
#   ],
# ]

The is method returns truthy or falsy based on the return value(s) of the "is" method specified, which should be defined as "is_${name}", which will be called automatically by this method. If no "is_${name}" method exists, this method will check if the "name" attribute is equal to the value provided.

is(string $name) (boolean)

{ since => '1.02', }

=example-1 is

package System::Error;

use Venus::Class;

base 'Venus::Error';

sub as_auth_error {
  my ($self) = @_;

  return $self->do('message', 'auth_error');
}

sub as_role_error {
  my ($self) = @_;

  return $self->do('message', 'role_error');
}

sub is_auth_error {
  my ($self) = @_;

  return $self->message eq 'auth_error';
}

sub is_role_error {
  my ($self) = @_;

  return $self->message eq 'role_error';
}

package main;

my $is = System::Error->new->as('auth_error')->is('auth_error');

# 1

The of method returns truthy or falsy based on the return value(s) of the "of" method specified, which should be defined as "of_${name}", which will be called automatically by this method. If no "of_${name}" method exists, this method will check if the "name" attribute contains the value provided.

of(string $name) (boolean)

{ since => '1.11', }

=example-1 of

package System::Error;

use Venus::Class;

base 'Venus::Error';

sub as_auth_error {
  my ($self) = @_;

  return $self->do('name', 'auth_error');
}

sub as_role_error {
  my ($self) = @_;

  return $self->do('name', 'role_error');
}

sub is_auth_error {
  my ($self) = @_;

  return $self->name eq 'auth_error';
}

sub is_role_error {
  my ($self) = @_;

  return $self->name eq 'role_error';
}

package main;

my $of = System::Error->as('auth_error')->of('role');

# 0

The render method replaces tokens in the message with values from the stash and returns the formatted string. The token style and formatting operation is equivalent to the "render" in Venus::String operation.

render() (string)

{ since => '3.30', }

The throw method throws an error if the invocant is an object, or creates an error object using the arguments provided and throws the created object.

throw(any @data) (Venus::Error)

{ since => '0.01', }

=example-1 throw

# given: synopsis;

my $throw = $error->throw;

# bless({ ... }, 'Venus::Error')

The trace method compiles a stack trace and returns the object. By default it skips the first frame.

trace(number $offset, number $limit) (Venus::Error)

{ since => '0.01', }

=example-1 trace

# given: synopsis;

my $trace = $error->trace;

# bless({ ... }, 'Venus::Error')

This package overloads the eq operator.

This package overloads the ne operator.

This package overloads the qr operator.

This package overloads the "" operator.

This package overloads the ~~ operator.

t/Venus.t: present: authors t/Venus.t: present: license

78 POD Errors

The following errors were encountered while parsing the POD:

Around line 14:

Unknown directive: =name

Around line 22:

Unknown directive: =tagline

Around line 30:

Unknown directive: =abstract

Around line 38:

Unknown directive: =includes

Around line 57:

Unknown directive: =synopsis

Around line 76:

Unknown directive: =description

Around line 88:

Unknown directive: =inherits

Around line 96:

Unknown directive: =integrates

Around line 105:

Unknown directive: =attributes

Around line 116:

Unknown directive: =method

Around line 123:

Unknown directive: =signature

Around line 127:

Unknown directive: =metadata

Around line 225:

=cut found outside a pod block. Skipping to next block.

Around line 255:

=cut found outside a pod block. Skipping to next block.

Around line 285:

=cut found outside a pod block. Skipping to next block.

Around line 297:

Unknown directive: =method

Around line 302:

Unknown directive: =signature

Around line 306:

Unknown directive: =metadata

Around line 322:

=cut found outside a pod block. Skipping to next block.

Around line 344:

=cut found outside a pod block. Skipping to next block.

Around line 366:

=cut found outside a pod block. Skipping to next block.

Around line 376:

Unknown directive: =method

Around line 381:

Unknown directive: =signature

Around line 385:

Unknown directive: =metadata

Around line 401:

=cut found outside a pod block. Skipping to next block.

Around line 423:

=cut found outside a pod block. Skipping to next block.

Around line 445:

=cut found outside a pod block. Skipping to next block.

Around line 455:

Unknown directive: =method

Around line 459:

Unknown directive: =signature

Around line 463:

Unknown directive: =metadata

Around line 479:

=cut found outside a pod block. Skipping to next block.

Around line 489:

Unknown directive: =method

Around line 494:

Unknown directive: =signature

Around line 498:

Unknown directive: =metadata

Around line 522:

Unknown directive: =method

Around line 528:

Unknown directive: =signature

Around line 532:

Unknown directive: =metadata

Around line 598:

=cut found outside a pod block. Skipping to next block.

Around line 618:

Unknown directive: =method

Around line 622:

Unknown directive: =signature

Around line 626:

Unknown directive: =metadata

Around line 659:

Unknown directive: =method

Around line 666:

Unknown directive: =signature

Around line 670:

Unknown directive: =metadata

Around line 762:

=cut found outside a pod block. Skipping to next block.

Around line 810:

=cut found outside a pod block. Skipping to next block.

Around line 834:

=cut found outside a pod block. Skipping to next block.

Around line 858:

=cut found outside a pod block. Skipping to next block.

Around line 868:

Unknown directive: =method

Around line 875:

Unknown directive: =signature

Around line 879:

Unknown directive: =metadata

Around line 971:

=cut found outside a pod block. Skipping to next block.

Around line 1019:

=cut found outside a pod block. Skipping to next block.

Around line 1043:

=cut found outside a pod block. Skipping to next block.

Around line 1067:

=cut found outside a pod block. Skipping to next block.

Around line 1077:

Unknown directive: =method

Around line 1083:

Unknown directive: =signature

Around line 1087:

Unknown directive: =metadata

Around line 1109:

=cut found outside a pod block. Skipping to next block.

Around line 1119:

Unknown directive: =method

Around line 1124:

Unknown directive: =signature

Around line 1128:

Unknown directive: =metadata

Around line 1152:

Unknown directive: =method

Around line 1157:

Unknown directive: =signature

Around line 1161:

Unknown directive: =metadata

Around line 1194:

=cut found outside a pod block. Skipping to next block.

Around line 1213:

=cut found outside a pod block. Skipping to next block.

Around line 1224:

Unknown directive: =operator

Around line 1240:

=cut found outside a pod block. Skipping to next block.

Around line 1250:

Unknown directive: =operator

Around line 1266:

=cut found outside a pod block. Skipping to next block.

Around line 1276:

Unknown directive: =operator

Around line 1292:

=cut found outside a pod block. Skipping to next block.

Around line 1302:

Unknown directive: =operator

Around line 1318:

=cut found outside a pod block. Skipping to next block.

Around line 1328:

Unknown directive: =operator

Around line 1344:

=cut found outside a pod block. Skipping to next block.

Around line 1350:

Unknown directive: =partials