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