Venus::Error

Error Class

Error Class for Perl 5

method: arguments method: as method: callframe method: capture method: captured method: copy method: explain method: frame method: frames method: get method: is method: input method: new method: of method: on method: output method: render method: reset method: set method: stash method: sysinfo method: system_name method: system_path method: system_perl_path method: system_perl_version method: system_process_id method: system_script_args method: system_script_path 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::Encaseable

The name attribute is read-write, accepts string values, and is optional.

name(string $name) (string)

{ since => '0.01', }

The cause attribute is read-write, accepts Venus::Error values, and is optional.

cause(Venus::Error $error) (Venus::Error)

{ since => '4.15', }

The context attribute is read-write, accepts string values, and is optional. Defaults to 'N/A'.

context(string $context) (string)

{ since => '0.01', }

The message attribute is read-write, accepts string values, and is optional. Defaults to 'Exception!'.

message(string $message) (string)

{ since => '0.01', }

The verbose attribute is read-write, accepts number values, and is optional. Defaults to true.

verbose(number $verbose) (number)

{ since => '0.01', }

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 capture method captures the caller info at the "frame" specified, in the object stash, and returns the invocant.

capture(any @args) (Venus::Error)

{ since => '4.15', }

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

captured() (hashref)

{ since => '2.55', }

The copy method copied the properties of the Venus::Error provided into the invocant and returns the invocant.

copy(Venus::Error $error) (Venus::Error)

{ since => '4.15', }

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

explain() (string)

{ since => '0.01', }

=example-1 explain

# given: synopsis;

$error->verbose(0);

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 get method takes one or more attribute and/or method names and returns the result of calling each attribute and/or method. In scalar context returns a single value. In list context results a list of values.

get(string @args) (any)

{ since => '4.15', }

The input method captures the arguments provided as associates them with a "callframe" based on the level specified by "offset", in the object stash, and returns the invocant.

input(any @args) (Venus::Error)

{ since => '4.15', }

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 new method constructs an instance of the package.

new(any @args) (Venus::Error)

{ since => '4.15', }

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 on method sets a "name" for the error in the form of "on.$subroutine.$name" or "on.$name" (if outside of a subroutine) and returns the invocant.

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

{ since => '4.15', }

The output method captures the arguments provided as associates them with a "callframe" based on the level specified by "offset", in the object stash, and returns the invocant.

output(any @args) (Venus::Error)

{ since => '4.15', }

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 reset method resets the "offset" and "verbose" attributes if they're not already set, resets the "context" based on the caller, and rebuilds the stacktrace, then returns the invocant.

reset() (Venus::Error)

{ since => '4.15', }

The set method sets one or more attributes and/or methods on the invocant. This method accepts key/value pairs or a hashref of key/value pairs and returns the invocant.

set(any @args) (any)

{ since => '4.15', }

The stash method gets and sets ad-hoc data related to the invocant.

stash(string $key, any $value) (any)

{ since => '4.15', }

The sysinfo method calls all the system_* methods and "stashes" the system information.

sysinfo() (Venus::Error)

{ since => '4.15', }

The system_name method "stashes" a value representing the "system name" and returns the invocant. If no value is provided this method will use $^O as the default.

system_name(string $value) (Venus::Error)

{ since => '4.15', }

The system_path method "stashes" a value representing the "system_path" and returns the invocant. If no value is provided this method will use Cwd/getcwd as the default.

system_path(string $value) (Venus::Error)

{ since => '4.15', }

The system_perl_path method "stashes" a value representing the "system_perl_path" and returns the invocant. If no value is provided this method will use $^X as the default.

system_perl_path(string $value) (Venus::Error)

{ since => '4.15', }

The system_perl_version method "stashes" a value representing the "system_perl_version" and returns the invocant. If no value is provided this method will use $^V as the default.

system_perl_version(string $value) (Venus::Error)

{ since => '4.15', }

The system_process_id method "stashes" a value representing the "system_process_id" and returns the invocant. If no value is provided this method will use $$ as the default.

system_process_id(string $value) (Venus::Error)

{ since => '4.15', }

The system_script_args method "stashes" a value representing the "system" and returns the invocant. If no value is provided this method will use [@ARGV] as the default.

system_script_args(string $value) (Venus::Error)

{ since => '4.15', }

The system_script_path method "stashes" a value representing the "system_script_path" and returns the invocant. If no value is provided this method will use $0 as the default.

system_script_path(string $value) (Venus::Error)

{ since => '4.15', }

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

198 POD Errors

The following errors were encountered while parsing the POD:

Around line 15:

Unknown directive: =name

Around line 23:

Unknown directive: =tagline

Around line 31:

Unknown directive: =abstract

Around line 39:

Unknown directive: =includes

Around line 76:

Unknown directive: =synopsis

Around line 95:

Unknown directive: =description

Around line 107:

Unknown directive: =inherits

Around line 115:

Unknown directive: =integrates

Around line 124:

Unknown directive: =attribute

Around line 128:

Unknown directive: =signature

Around line 132:

Unknown directive: =metadata

Around line 150:

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

Around line 172:

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

Around line 182:

Unknown directive: =attribute

Around line 187:

Unknown directive: =signature

Around line 191:

Unknown directive: =metadata

Around line 209:

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

Around line 231:

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

Around line 241:

Unknown directive: =attribute

Around line 246:

Unknown directive: =signature

Around line 250:

Unknown directive: =metadata

Around line 268:

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

Around line 290:

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

Around line 300:

Unknown directive: =attribute

Around line 305:

Unknown directive: =signature

Around line 309:

Unknown directive: =metadata

Around line 327:

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

Around line 349:

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

Around line 359:

Unknown directive: =attribute

Around line 364:

Unknown directive: =signature

Around line 368:

Unknown directive: =metadata

Around line 386:

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

Around line 408:

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

Around line 418:

Unknown directive: =method

Around line 425:

Unknown directive: =signature

Around line 429:

Unknown directive: =metadata

Around line 527:

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

Around line 557:

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

Around line 587:

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

Around line 599:

Unknown directive: =method

Around line 604:

Unknown directive: =signature

Around line 608:

Unknown directive: =metadata

Around line 624:

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

Around line 646:

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

Around line 668:

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

Around line 678:

Unknown directive: =method

Around line 683:

Unknown directive: =signature

Around line 687:

Unknown directive: =metadata

Around line 703:

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

Around line 725:

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

Around line 747:

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

Around line 757:

Unknown directive: =method

Around line 762:

Unknown directive: =signature

Around line 766:

Unknown directive: =metadata

Around line 784:

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

Around line 797:

Unknown directive: =method

Around line 801:

Unknown directive: =signature

Around line 805:

Unknown directive: =metadata

Around line 821:

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

Around line 831:

Unknown directive: =method

Around line 836:

Unknown directive: =signature

Around line 840:

Unknown directive: =metadata

Around line 864:

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

Around line 903:

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

Around line 916:

Unknown directive: =method

Around line 921:

Unknown directive: =signature

Around line 925:

Unknown directive: =metadata

Around line 961:

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

Around line 1000:

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

Around line 1041:

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

Around line 1095:

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

Around line 1129:

Unknown directive: =method

Around line 1135:

Unknown directive: =signature

Around line 1139:

Unknown directive: =metadata

Around line 1205:

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

Around line 1225:

Unknown directive: =method

Around line 1229:

Unknown directive: =signature

Around line 1233:

Unknown directive: =metadata

Around line 1266:

Unknown directive: =method

Around line 1272:

Unknown directive: =signature

Around line 1276:

Unknown directive: =metadata

Around line 1294:

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

Around line 1314:

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

Around line 1334:

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

Around line 1344:

Unknown directive: =method

Around line 1350:

Unknown directive: =signature

Around line 1354:

Unknown directive: =metadata

Around line 1372:

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

Around line 1386:

Unknown directive: =method

Around line 1393:

Unknown directive: =signature

Around line 1397:

Unknown directive: =metadata

Around line 1489:

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

Around line 1537:

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

Around line 1561:

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

Around line 1585:

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

Around line 1595:

Unknown directive: =method

Around line 1599:

Unknown directive: =signature

Around line 1603:

Unknown directive: =metadata

Around line 1621:

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

Around line 1642:

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

Around line 1663:

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

Around line 1674:

Unknown directive: =method

Around line 1681:

Unknown directive: =signature

Around line 1685:

Unknown directive: =metadata

Around line 1777:

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

Around line 1825:

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

Around line 1849:

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

Around line 1873:

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

Around line 1883:

Unknown directive: =method

Around line 1889:

Unknown directive: =signature

Around line 1893:

Unknown directive: =metadata

Around line 1915:

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

Around line 1926:

Unknown directive: =method

Around line 1932:

Unknown directive: =signature

Around line 1936:

Unknown directive: =metadata

Around line 1954:

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

Around line 1968:

Unknown directive: =method

Around line 1974:

Unknown directive: =signature

Around line 1978:

Unknown directive: =metadata

Around line 2000:

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

Around line 2010:

Unknown directive: =method

Around line 2016:

Unknown directive: =signature

Around line 2020:

Unknown directive: =metadata

Around line 2038:

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

Around line 2063:

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

Around line 2076:

Unknown directive: =method

Around line 2082:

Unknown directive: =signature

Around line 2086:

Unknown directive: =metadata

Around line 2104:

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

Around line 2125:

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

Around line 2147:

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

Around line 2159:

Unknown directive: =method

Around line 2163:

Unknown directive: =signature

Around line 2167:

Unknown directive: =metadata

Around line 2185:

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

Around line 2205:

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

Around line 2225:

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

Around line 2247:

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

Around line 2270:

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

Around line 2296:

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

Around line 2309:

Unknown directive: =method

Around line 2314:

Unknown directive: =signature

Around line 2318:

Unknown directive: =metadata

Around line 2368:

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

Around line 2387:

Unknown directive: =method

Around line 2393:

Unknown directive: =signature

Around line 2397:

Unknown directive: =metadata

Around line 2419:

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

Around line 2444:

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

Around line 2455:

Unknown directive: =method

Around line 2461:

Unknown directive: =signature

Around line 2465:

Unknown directive: =metadata

Around line 2487:

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

Around line 2516:

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

Around line 2529:

Unknown directive: =method

Around line 2535:

Unknown directive: =signature

Around line 2539:

Unknown directive: =metadata

Around line 2561:

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

Around line 2586:

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

Around line 2597:

Unknown directive: =method

Around line 2603:

Unknown directive: =signature

Around line 2607:

Unknown directive: =metadata

Around line 2629:

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

Around line 2654:

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

Around line 2665:

Unknown directive: =method

Around line 2671:

Unknown directive: =signature

Around line 2675:

Unknown directive: =metadata

Around line 2697:

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

Around line 2722:

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

Around line 2733:

Unknown directive: =method

Around line 2739:

Unknown directive: =signature

Around line 2743:

Unknown directive: =metadata

Around line 2765:

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

Around line 2790:

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

Around line 2801:

Unknown directive: =method

Around line 2807:

Unknown directive: =signature

Around line 2811:

Unknown directive: =metadata

Around line 2833:

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

Around line 2858:

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

Around line 2869:

Unknown directive: =method

Around line 2874:

Unknown directive: =signature

Around line 2878:

Unknown directive: =metadata

Around line 2902:

Unknown directive: =method

Around line 2907:

Unknown directive: =signature

Around line 2911:

Unknown directive: =metadata

Around line 2944:

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

Around line 2963:

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

Around line 2974:

Unknown directive: =operator

Around line 2990:

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

Around line 3000:

Unknown directive: =operator

Around line 3016:

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

Around line 3026:

Unknown directive: =operator

Around line 3042:

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

Around line 3052:

Unknown directive: =operator

Around line 3068:

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

Around line 3078:

Unknown directive: =operator

Around line 3094:

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

Around line 3100:

Unknown directive: =partials