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).
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:
as(Str $name) (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)
explain() (Str)
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(Int $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(Str $name) (Bool)
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(Str $name) (Bool)
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
throw(Any @data) (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(Int $offset, Int $limit) (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:
(eq)
This package overloads the eq operator.
eq
example 1
# 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!"
(~~)
This package overloads the ~~ operator.
~~
# given: synopsis; my $result = $error ~~ 'Exception!'; # 1
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.