Venus::Role::Catchable

Catchable Role

Catchable Role for Perl 5

method: catch 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 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

18 POD Errors

The following errors were encountered while parsing the POD:

Around line 13:

Unknown directive: =name

Around line 21:

Unknown directive: =tagline

Around line 29:

Unknown directive: =abstract

Around line 37:

Unknown directive: =includes

Around line 46:

Unknown directive: =synopsis

Around line 82:

Unknown directive: =description

Around line 91:

Unknown directive: =method

Around line 99:

Unknown directive: =signature

Around line 103:

Unknown directive: =metadata

Around line 139:

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

Around line 159:

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

Around line 180:

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

Around line 191:

Unknown directive: =method

Around line 199:

Unknown directive: =signature

Around line 203:

Unknown directive: =metadata

Around line 239:

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

Around line 260:

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

Around line 270:

Unknown directive: =partials