Venus::Error

Error Class

Error Class for Perl 5

method: as method: explain method: frame method: frames method: is method: of 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(Str $name) (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 explain method returns the error message and is used in stringification operations.

explain() (Str)

{ 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(Int $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(Str $name) (Bool)

{ 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(Str $name) (Bool)

{ 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 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) (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(Int $offset, Int $limit) (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: pdml: authors t/Venus.t: pdml: license

58 POD Errors

The following errors were encountered while parsing the POD:

Around line 13:

Unknown directive: =name

Around line 21:

Unknown directive: =tagline

Around line 29:

Unknown directive: =abstract

Around line 37:

Unknown directive: =includes

Around line 52:

Unknown directive: =synopsis

Around line 71:

Unknown directive: =description

Around line 83:

Unknown directive: =inherits

Around line 91:

Unknown directive: =integrates

Around line 100:

Unknown directive: =attributes

Around line 111:

Unknown directive: =method

Around line 118:

Unknown directive: =signature

Around line 122:

Unknown directive: =metadata

Around line 220:

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

Around line 250:

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

Around line 280:

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

Around line 292:

Unknown directive: =method

Around line 297:

Unknown directive: =signature

Around line 301:

Unknown directive: =metadata

Around line 325:

Unknown directive: =method

Around line 331:

Unknown directive: =signature

Around line 335:

Unknown directive: =metadata

Around line 401:

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

Around line 421:

Unknown directive: =method

Around line 425:

Unknown directive: =signature

Around line 429:

Unknown directive: =metadata

Around line 462:

Unknown directive: =method

Around line 469:

Unknown directive: =signature

Around line 473:

Unknown directive: =metadata

Around line 565:

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

Around line 613:

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

Around line 637:

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

Around line 661:

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

Around line 671:

Unknown directive: =method

Around line 678:

Unknown directive: =signature

Around line 682:

Unknown directive: =metadata

Around line 774:

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

Around line 822:

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

Around line 846:

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

Around line 870:

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

Around line 880:

Unknown directive: =method

Around line 885:

Unknown directive: =signature

Around line 889:

Unknown directive: =metadata

Around line 913:

Unknown directive: =method

Around line 918:

Unknown directive: =signature

Around line 922:

Unknown directive: =metadata

Around line 955:

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

Around line 974:

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

Around line 985:

Unknown directive: =operator

Around line 1001:

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

Around line 1011:

Unknown directive: =operator

Around line 1027:

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

Around line 1037:

Unknown directive: =operator

Around line 1053:

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

Around line 1063:

Unknown directive: =operator

Around line 1079:

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

Around line 1089:

Unknown directive: =operator

Around line 1105:

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

Around line 1111:

Unknown directive: =partials