| 1 | package Venus::Role::Tryable; | ||||||||||
| 2 | |||||||||||
| 3 | 119 | ▶ | use 5.018; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 119 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 119 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # IMPORTS | ||||||||||
| 9 | |||||||||||
| 10 | 119 | ▶ | use Venus::Role 'with'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | # METHODS | ||||||||||
| 13 | |||||||||||
| 14 | 18171 | ▶ | sub try { | ||||||||
|
Subroutine
try: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 15 | 18171 | my ($self, $callback, @args) = @_; | |||||||||
| 16 | |||||||||||
| 17 | 18171 | require Venus::Try; | |||||||||
| 18 | |||||||||||
| 19 | 18171 | my $try = Venus::Try->new(invocant => $self, arguments => [@args]); | |||||||||
| 20 | |||||||||||
| 21 | 18171 | ▶ | return $try if !$callback; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 18171 | return $try->call($callback); | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | # EXPORTS | ||||||||||
| 27 | |||||||||||
| 28 | 129 | ▶ | sub EXPORT { | ||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 29 | 129 | ['try'] | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 119 | 1; | |||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | =head1 NAME | ||||||||||
| 37 | |||||||||||
| 38 | Venus::Role::Tryable - Tryable Role | ||||||||||
| 39 | |||||||||||
| 40 | =cut | ||||||||||
| 41 | |||||||||||
| 42 | =head1 ABSTRACT | ||||||||||
| 43 | |||||||||||
| 44 | Tryable Role for Perl 5 | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||
| 49 | |||||||||||
| 50 | package Example; | ||||||||||
| 51 | |||||||||||
| 52 | use Venus::Class 'with'; | ||||||||||
| 53 | use Venus 'raise'; | ||||||||||
| 54 | |||||||||||
| 55 | with 'Venus::Role::Tryable'; | ||||||||||
| 56 | |||||||||||
| 57 | sub test { | ||||||||||
| 58 | raise 'Example::Error'; | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | package main; | ||||||||||
| 62 | |||||||||||
| 63 | my $example = Example->new; | ||||||||||
| 64 | |||||||||||
| 65 | # $example->try('test'); | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | =head1 DESCRIPTION | ||||||||||
| 70 | |||||||||||
| 71 | This package modifies the consuming package and provides a mechanism for | ||||||||||
| 72 | handling potentially volatile routines. | ||||||||||
| 73 | |||||||||||
| 74 | =cut | ||||||||||
| 75 | |||||||||||
| 76 | =head1 METHODS | ||||||||||
| 77 | |||||||||||
| 78 | This package provides the following methods: | ||||||||||
| 79 | |||||||||||
| 80 | =cut | ||||||||||
| 81 | |||||||||||
| 82 | =head2 try | ||||||||||
| 83 | |||||||||||
| 84 | try(string | coderef $method, any @args) (Venus::Try) | ||||||||||
| 85 | |||||||||||
| 86 | The try method returns a L<Venus::Try> object having the invocant, callback, | ||||||||||
| 87 | arguments pre-configured. This method supports dispatching, i.e. providing a | ||||||||||
| 88 | method name and arguments whose return value will be acted on by this method. | ||||||||||
| 89 | |||||||||||
| 90 | I<Since C<0.01>> | ||||||||||
| 91 | |||||||||||
| 92 | =over 4 | ||||||||||
| 93 | |||||||||||
| 94 | =item try example 1 | ||||||||||
| 95 | |||||||||||
| 96 | package main; | ||||||||||
| 97 | |||||||||||
| 98 | my $example = Example->new; | ||||||||||
| 99 | |||||||||||
| 100 | my $try = $example->try('test'); | ||||||||||
| 101 | |||||||||||
| 102 | # my $value = $try->result; | ||||||||||
| 103 | |||||||||||
| 104 | =back | ||||||||||
| 105 | |||||||||||
| 106 | =cut | ||||||||||
| 107 | |||||||||||
| 108 | =head1 AUTHORS | ||||||||||
| 109 | |||||||||||
| 110 | Awncorp, C<awncorp@cpan.org> | ||||||||||
| 111 | |||||||||||
| 112 | =cut | ||||||||||
| 113 | |||||||||||
| 114 | =head1 LICENSE | ||||||||||
| 115 | |||||||||||
| 116 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||
| 117 | |||||||||||
| 118 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 119 | the terms of the Apache license version 2.0. | ||||||||||
| 120 | |||||||||||
| 121 | =cut | ||||||||||