Venus::Role::Catchable

Catchable Role

Catchable Role for Perl 5

method: catch method: caught method: maybe

package Example;

use Venus::Class;

use Venus 'error';

with 'Venus::Role::Tryable';
with 'Venus::Role::Catchable';

sub pass {
  true;
}

sub fail {
  error;
}

package main;

my $example = Example->new;

# my $error = $example->catch('fail');

This package modifies the consuming package and provides methods for trapping errors thrown from dispatched method calls.

The catch method traps any errors raised by executing the dispatched method call and returns the error string or error object. This method can return a list of values in list-context. This method supports dispatching, i.e. providing a method name and arguments whose return value will be acted on by this method.

catch(string $method, any @args) (any)

{ since => '0.01', }

=example-1 catch

package main;

my $example = Example->new;

my $catch = $example->catch('fail');

# bless({...}, "Venus::Error")

The caught method evaluates the value provided and validates its identity and name (if provided) then executes the code block (if provided) returning the result of the callback. If no callback is provided this function returns the exception object on success and undef on failure.

caught(object $error, string | tuple[string, string] $identity, coderef $block) (any)

{ since => '4.15', }

=example-1 caught

package main;

my $example = Example->new;

my $catch = $example->catch('fail');

my $result = $example->caught($catch);

# bless(..., 'Venus::Error')

The maybe method traps any errors raised by executing the dispatched method call and returns undefined on error, effectively supressing the error. This method can return a list of values in list-context. This method supports dispatching, i.e. providing a method name and arguments whose return value will be acted on by this method.

maybe(string $method, any @args) (any)

{ since => '2.91', }

=example-1 maybe

package main;

my $example = Example->new;

my $maybe = $example->maybe('fail');

# undef

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

28 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 84:

Unknown directive: =description

Around line 93:

Unknown directive: =method

Around line 101:

Unknown directive: =signature

Around line 105:

Unknown directive: =metadata

Around line 141:

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

Around line 161:

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

Around line 182:

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

Around line 193:

Unknown directive: =method

Around line 200:

Unknown directive: =signature

Around line 204:

Unknown directive: =metadata

Around line 245:

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

Around line 272:

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

Around line 299:

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

Around line 328:

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

Around line 353:

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

Around line 375:

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

Around line 397:

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

Around line 407:

Unknown directive: =method

Around line 415:

Unknown directive: =signature

Around line 419:

Unknown directive: =metadata

Around line 455:

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

Around line 476:

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

Around line 486:

Unknown directive: =partials