Venus::Role::Throwable

Throwable Role

Throwable Role for Perl 5

method: die method: error method: throw

package Example;

use Venus::Class;

with 'Venus::Role::Throwable';

package main;

my $example = Example->new;

# $example->throw;

This package modifies the consuming package and provides a mechanism for throwing context-aware errors (exceptions).

The die method builds a Venus::Throw object using "throw" and automatically throws the exception.

die(maybe[string | hashref] $data) (any)

{ since => '4.15', }

=example-1 die

# given: synopsis

package Example;

# ...

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

  return {
    name => 'on.example',
    capture => [$example],
    stash => {
      time => time,
    },
    raise => true,
  };
}

package main;

my $die = $example->die('error_on_example');

# Exception! isa Example::Error

The error method dispatches to the "throw" method, excepts a hashref of options to be provided to the "throw" method, and returns the result unless an exception is raised automatically. If the throw option is provided it is excepted to be the name of a method used as a callback to provide arguments to the thrower.

error(maybe[string | hashref] $data) (any)

{ since => '3.40', }

The throw method builds a Venus::Throw object, which can raise errors (exceptions). If passed a string representing a package name, the throw object will be configured to throw an exception using that package name. If passed a string representing a method name, the throw object will call that method expecting a hashref to be returned which will be provided to Venus::Throw as arguments to configure the thrower. If passed a hashref, the keys and values are expected to be method names and arguments which will be called to configure the Venus::Throw object returned. If passed additional arguments, assuming they are preceeded by a string representing a method name, the additional arguments will be supplied to the method when called. If the raise argument is provided (or returned from the callback), the thrower will automatically throw the exception.

throw(maybe[string | hashref] $data, any @args) (any)

{ since => '0.01', }

=example-1 throw

package main;

my $example = Example->new;

my $throw = $example->throw;

# bless({"package" => "Example::Error", ...,}, "Venus::Throw")

# $throw->die;

# Exception! isa Example::Error

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

25 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 48:

Unknown directive: =synopsis

Around line 73:

Unknown directive: =description

Around line 82:

Unknown directive: =method

Around line 87:

Unknown directive: =signature

Around line 91:

Unknown directive: =metadata

Around line 136:

Unknown directive: =method

Around line 144:

Unknown directive: =signature

Around line 148:

Unknown directive: =metadata

Around line 170:

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

Around line 194:

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

Around line 224:

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

Around line 267:

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

Around line 311:

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

Around line 350:

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

Around line 362:

Unknown directive: =method

Around line 377:

Unknown directive: =signature

Around line 381:

Unknown directive: =metadata

Around line 426:

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

Around line 457:

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

Around line 501:

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

Around line 515:

Unknown directive: =partials