Venus::Error - Error Class
Error Class for Perl 5
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_ERROR_VERBOSE
0
VENUS_ERROR_TRACE_OFFSET
This package has the following attributes:
name(Str)
This attribute is read-write, accepts (Str) values, and is optional.
(Str)
context(Str)
This attribute is read-write, accepts (Str) values, is optional, and defaults to '(None)'.
'(None)'
message(Str)
This attribute is read-write, accepts (Str) values, is optional, and defaults to 'Exception!'.
'Exception!'
verbose(Int)
This attribute is read-write, accepts (Int) values, is optional, and defaults to 1.
(Int)
1
This package inherits behaviors from:
Venus::Kind::Utility
This package integrates behaviors from:
Venus::Role::Explainable
Venus::Role::Stashable
This package provides the following methods:
arguments(number $index) (any)
The arguments method returns the stashed arguments under "captured", or a specific argument if an index is provided.
Since 2.55
2.55
# given: synopsis my $arguments = $error->arguments; # undef
package main; use Venus::Throw; my $error = Venus::Throw->new->capture(1..4)->catch('error'); my $arguments = $error->arguments; # [1..4]
package main; use Venus::Throw; my $error = Venus::Throw->new->capture(1..4)->catch('error'); my $arguments = $error->arguments(0); # 1
as(string $name) (Venus::Error)
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_${name}"
Since 1.02
1.02
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)
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('role_error'); $error->throw; # Exception! (isa Venus::Error)
package Virtual::Error; use Venus::Class; base 'Venus::Error'; package main; my $error = Virtual::Error->new->as('on_save_error'); $error->throw; # name is "on_save_error" # Exception! (isa Venus::Error)
package Virtual::Error; use Venus::Class; base 'Venus::Error'; package main; my $error = Virtual::Error->new->as('on.SAVE.error'); $error->throw; # name is "on_save_error" # Exception! (isa Venus::Error)
callframe(number $index) (any)
The callframe method returns the stashed callframe under "captured", or a specific argument if an index is provided.
# given: synopsis my $callframe = $error->callframe; # undef
package main; use Venus::Throw; my $error = Venus::Throw->new->do('frame', 0)->capture->catch('error'); my $callframe = $error->callframe; # [...]
package main; use Venus::Throw; my $error = Venus::Throw->new->do('frame', 0)->capture->catch('error'); my $package = $error->callframe(0); # 'main'
captured() (hashref)
The captured method returns the value stashed as "captured".
"captured"
# given: synopsis my $captured = $error->captured; # undef
explain() (string)
The explain method returns the error message and is used in stringification operations.
Since 0.01
0.01
# given: synopsis; my $explain = $error->explain; # "Exception! in ...
frame(number $index) (hashref)
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.
caller
Since 1.11
1.11
# given: synopsis; my $frame = $error->frame; # { # 'bitmask' => '...', # 'evaltext' => '...', # 'filename' => '...', # 'hasargs' => '...', # 'hinthash' => '...', # 'hints' => '...', # 'is_require' => '...', # 'line' => '...', # 'package' => '...', # 'subroutine' => '...', # 'wantarray' => '...', # }
# given: synopsis; my $frame = $error->frame(1); # { # 'bitmask' => '...', # 'evaltext' => '...', # 'filename' => '...', # 'hasargs' => '...', # 'hinthash' => '...', # 'hints' => '...', # 'is_require' => '...', # 'line' => '...', # 'package' => '...', # 'subroutine' => '...', # 'wantarray' => '...', # }
frames() (arrayref)
The frames method returns the compiled and stashed stack trace data.
# given: synopsis; my $frames = $error->frames; # [ # ... # [ # "main", # "t/Venus_Error.t", # ... # ], # ]
is(string $name) (boolean)
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_${name}"
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
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->as('auth_error')->is('auth_error'); # 1
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->as('auth_error')->is('role_error'); # 0
package Virtual::Error; use Venus::Class; base 'Venus::Error'; package main; my $is = Virtual::Error->new->as('on_save_error')->is('on_save_error'); # 1
package Virtual::Error; use Venus::Class; base 'Venus::Error'; package main; my $is = Virtual::Error->new->as('on.SAVE.error')->is('on_save_error'); # 1
of(string $name) (boolean)
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_${name}"
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
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('auth'); # 1
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_error'); # 0
package Virtual::Error; use Venus::Class; base 'Venus::Error'; package main; my $of = Virtual::Error->new->as('on_save_error')->of('on.save'); # 1
package Virtual::Error; use Venus::Class; base 'Venus::Error'; package main; my $of = Virtual::Error->new->as('on.SAVE.error')->of('on.save'); # 1
render() (string)
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.
Since 3.30
3.30
# given: synopsis package main; $error->message('Signal received: {{signal}}'); $error->stash(signal => 'SIGKILL'); my $render = $error->render; # "Signal received: SIGKILL"
throw(any @data) (Venus::Error)
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.
# given: synopsis; my $throw = $error->throw; # bless({ ... }, 'Venus::Error')
trace(number $offset, number $limit) (Venus::Error)
The trace method compiles a stack trace and returns the object. By default it skips the first frame.
# given: synopsis; my $trace = $error->trace; # bless({ ... }, 'Venus::Error')
# given: synopsis; my $trace = $error->trace(0, 1); # bless({ ... }, 'Venus::Error')
# given: synopsis; my $trace = $error->trace(0, 2); # bless({ ... }, 'Venus::Error')
This package overloads the following operators:
("")
This package overloads the "" operator.
""
example 1
# given: synopsis; my $result = "$error"; # "Exception!"
(eq)
This package overloads the eq operator.
eq
# given: synopsis; my $result = $error eq 'Exception!'; # 1
(ne)
This package overloads the ne operator.
ne
# given: synopsis; my $result = $error ne 'exception!'; # 1
(qr)
This package overloads the qr operator.
qr
# given: synopsis; my $test = 'Exception!' =~ qr/$error/; # 1
(~~)
This package overloads the ~~ operator.
~~
# given: synopsis; my $result = $error ~~ 'Exception!'; # 1
Awncorp, awncorp@cpan.org
awncorp@cpan.org
Copyright (C) 2000, Awncorp, awncorp@cpan.org.
This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.