| 1 | package Venus::Role::Catchable; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 61 | ▶ | use 5.018; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 61 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 61 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 61 | ▶ | use Venus::Role 'with'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 61 | with 'Venus::Role::Tryable'; | |||||||||||||
| 11 | |||||||||||||||
| 12 | # METHODS | ||||||||||||||
| 13 | |||||||||||||||
| 14 | sub catch { | ||||||||||||||
| 15 | 48 | ▶ | my ($self, $method, @args) = @_; | ||||||||||||
|
Subroutine
catch: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 48 | my @result = $self->try($method, @args)->error(\my $error)->result; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 48 | ▶ | return wantarray ? ($error ? ($error, undef) : ($error, @result)) : $error; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 20 | } | ||||||||||||||
| 21 | |||||||||||||||
| 22 | # EXPORTS | ||||||||||||||
| 23 | |||||||||||||||
| 24 | sub EXPORT { | ||||||||||||||
| 25 | 63 | ▶ | ['catch', 'try'] | ||||||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 61 | 1; | |||||||||||||
| 29 | |||||||||||||||
| 30 | |||||||||||||||
| 31 | |||||||||||||||
| 32 | =head1 NAME | ||||||||||||||
| 33 | |||||||||||||||
| 34 | Venus::Role::Catchable - Catchable Role | ||||||||||||||
| 35 | |||||||||||||||
| 36 | =cut | ||||||||||||||
| 37 | |||||||||||||||
| 38 | =head1 ABSTRACT | ||||||||||||||
| 39 | |||||||||||||||
| 40 | Catchable Role for Perl 5 | ||||||||||||||
| 41 | |||||||||||||||
| 42 | =cut | ||||||||||||||
| 43 | |||||||||||||||
| 44 | =head1 SYNOPSIS | ||||||||||||||
| 45 | |||||||||||||||
| 46 | package Example; | ||||||||||||||
| 47 | |||||||||||||||
| 48 | use Venus::Class; | ||||||||||||||
| 49 | |||||||||||||||
| 50 | use Venus 'error'; | ||||||||||||||
| 51 | |||||||||||||||
| 52 | with 'Venus::Role::Catchable'; | ||||||||||||||
| 53 | |||||||||||||||
| 54 | sub pass { | ||||||||||||||
| 55 | true; | ||||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | sub fail { | ||||||||||||||
| 59 | error; | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | package main; | ||||||||||||||
| 63 | |||||||||||||||
| 64 | my $example = Example->new; | ||||||||||||||
| 65 | |||||||||||||||
| 66 | # my $error = $example->catch('fail'); | ||||||||||||||
| 67 | |||||||||||||||
| 68 | =cut | ||||||||||||||
| 69 | |||||||||||||||
| 70 | =head1 DESCRIPTION | ||||||||||||||
| 71 | |||||||||||||||
| 72 | This package modifies the consuming package and provides methods for trapping | ||||||||||||||
| 73 | errors thrown from dispatched method calls. | ||||||||||||||
| 74 | |||||||||||||||
| 75 | =cut | ||||||||||||||
| 76 | |||||||||||||||
| 77 | =head1 INTEGRATES | ||||||||||||||
| 78 | |||||||||||||||
| 79 | This package integrates behaviors from: | ||||||||||||||
| 80 | |||||||||||||||
| 81 | L<Venus::Role::Tryable> | ||||||||||||||
| 82 | |||||||||||||||
| 83 | =cut | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =head1 METHODS | ||||||||||||||
| 86 | |||||||||||||||
| 87 | This package provides the following methods: | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =cut | ||||||||||||||
| 90 | |||||||||||||||
| 91 | =head2 catch | ||||||||||||||
| 92 | |||||||||||||||
| 93 | catch(Str $method, Any @args) (Any) | ||||||||||||||
| 94 | |||||||||||||||
| 95 | The catch method traps any errors raised by executing the dispatched method | ||||||||||||||
| 96 | call and returns the error string or error object. This method can return a | ||||||||||||||
| 97 | list of values in list-context. This method supports dispatching, i.e. | ||||||||||||||
| 98 | providing a method name and arguments whose return value will be acted on by | ||||||||||||||
| 99 | this method. | ||||||||||||||
| 100 | |||||||||||||||
| 101 | I<Since C<0.01>> | ||||||||||||||
| 102 | |||||||||||||||
| 103 | =over 4 | ||||||||||||||
| 104 | |||||||||||||||
| 105 | =item catch example 1 | ||||||||||||||
| 106 | |||||||||||||||
| 107 | package main; | ||||||||||||||
| 108 | |||||||||||||||
| 109 | my $example = Example->new; | ||||||||||||||
| 110 | |||||||||||||||
| 111 | my $catch = $example->catch('fail'); | ||||||||||||||
| 112 | |||||||||||||||
| 113 | # bless({...}, "Venus::Error") | ||||||||||||||
| 114 | |||||||||||||||
| 115 | =back | ||||||||||||||
| 116 | |||||||||||||||
| 117 | =over 4 | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =item catch example 2 | ||||||||||||||
| 120 | |||||||||||||||
| 121 | package main; | ||||||||||||||
| 122 | |||||||||||||||
| 123 | my $example = Example->new; | ||||||||||||||
| 124 | |||||||||||||||
| 125 | my $catch = $example->catch('pass'); | ||||||||||||||
| 126 | |||||||||||||||
| 127 | # undef | ||||||||||||||
| 128 | |||||||||||||||
| 129 | =back | ||||||||||||||
| 130 | |||||||||||||||
| 131 | =over 4 | ||||||||||||||
| 132 | |||||||||||||||
| 133 | =item catch example 3 | ||||||||||||||
| 134 | |||||||||||||||
| 135 | package main; | ||||||||||||||
| 136 | |||||||||||||||
| 137 | my $example = Example->new; | ||||||||||||||
| 138 | |||||||||||||||
| 139 | my ($catch, $result) = $example->catch('pass'); | ||||||||||||||
| 140 | |||||||||||||||
| 141 | # (undef, 1) | ||||||||||||||
| 142 | |||||||||||||||
| 143 | =back | ||||||||||||||
| 144 | |||||||||||||||
| 145 | =over 4 | ||||||||||||||
| 146 | |||||||||||||||
| 147 | =item catch example 4 | ||||||||||||||
| 148 | |||||||||||||||
| 149 | package main; | ||||||||||||||
| 150 | |||||||||||||||
| 151 | my $example = Example->new; | ||||||||||||||
| 152 | |||||||||||||||
| 153 | my ($catch, $result) = $example->catch('fail'); | ||||||||||||||
| 154 | |||||||||||||||
| 155 | # (bless({...}, "Venus::Error"), undef) | ||||||||||||||
| 156 | |||||||||||||||
| 157 | =back | ||||||||||||||
| 158 | |||||||||||||||
| 159 | =cut | ||||||||||||||