| 1 | package Venus::Role::Resultable; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.018; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # IMPORTS | ||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Venus::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | # METHODS | ||||||||||
| 13 | |||||||||||
| 14 | 4 | ▶ | sub result { | ||||||||
|
Subroutine
result: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 15 | 4 | my ($self, $code, @args) = @_; | |||||||||
| 16 | |||||||||||
| 17 | 4 | require Venus::Result; | |||||||||
| 18 | |||||||||||
| 19 | 4 | my $result = Venus::Result->new; | |||||||||
| 20 | |||||||||||
| 21 | 4 | ▶ | $result = $result->then(sub{$self->$code(@args)}) if $code; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 4 | return $result; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | # EXPORTS | ||||||||||
| 27 | |||||||||||
| 28 | 4 | ▶ | sub EXPORT { | ||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 29 | 4 | ['result'] | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 1 | 1; | |||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | =head1 NAME | ||||||||||
| 37 | |||||||||||
| 38 | Venus::Role::Resultable - Resultable Role | ||||||||||
| 39 | |||||||||||
| 40 | =cut | ||||||||||
| 41 | |||||||||||
| 42 | =head1 ABSTRACT | ||||||||||
| 43 | |||||||||||
| 44 | Resultable Role for Perl 5 | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||
| 49 | |||||||||||
| 50 | package Example; | ||||||||||
| 51 | |||||||||||
| 52 | use Venus::Class; | ||||||||||
| 53 | |||||||||||
| 54 | with 'Venus::Role::Resultable'; | ||||||||||
| 55 | |||||||||||
| 56 | sub fail { | ||||||||||
| 57 | die 'failed'; | ||||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | sub pass { | ||||||||||
| 61 | return 'passed'; | ||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | package main; | ||||||||||
| 65 | |||||||||||
| 66 | my $example = Example->new; | ||||||||||
| 67 | |||||||||||
| 68 | # $example->result('fail'); | ||||||||||
| 69 | |||||||||||
| 70 | # bless(..., "Venus::Result") | ||||||||||
| 71 | |||||||||||
| 72 | =cut | ||||||||||
| 73 | |||||||||||
| 74 | =head1 DESCRIPTION | ||||||||||
| 75 | |||||||||||
| 76 | This package modifies the consuming package and provides a mechanism for | ||||||||||
| 77 | returning dynamically dispatched subroutine calls as L<Venus::Result> objects. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | =head1 METHODS | ||||||||||
| 82 | |||||||||||
| 83 | This package provides the following methods: | ||||||||||
| 84 | |||||||||||
| 85 | =cut | ||||||||||
| 86 | |||||||||||
| 87 | =head2 result | ||||||||||
| 88 | |||||||||||
| 89 | result(string | coderef $callback, any @args) (Venus::Result) | ||||||||||
| 90 | |||||||||||
| 91 | The result method dispatches to the named method or coderef provided and | ||||||||||
| 92 | returns a L<Venus::Result> object containing the error or return value | ||||||||||
| 93 | encountered. | ||||||||||
| 94 | |||||||||||
| 95 | I<Since C<4.15>> | ||||||||||
| 96 | |||||||||||
| 97 | =over 4 | ||||||||||
| 98 | |||||||||||
| 99 | =item result example 1 | ||||||||||
| 100 | |||||||||||
| 101 | # given: synopsis; | ||||||||||
| 102 | |||||||||||
| 103 | my $result = $example->result; | ||||||||||
| 104 | |||||||||||
| 105 | # bless(..., "Venus::Result") | ||||||||||
| 106 | |||||||||||
| 107 | =back | ||||||||||
| 108 | |||||||||||
| 109 | =over 4 | ||||||||||
| 110 | |||||||||||
| 111 | =item result example 2 | ||||||||||
| 112 | |||||||||||
| 113 | # given: synopsis; | ||||||||||
| 114 | |||||||||||
| 115 | my $result = $example->result('pass'); | ||||||||||
| 116 | |||||||||||
| 117 | # bless(..., "Venus::Result") | ||||||||||
| 118 | |||||||||||
| 119 | =back | ||||||||||
| 120 | |||||||||||
| 121 | =over 4 | ||||||||||
| 122 | |||||||||||
| 123 | =item result example 3 | ||||||||||
| 124 | |||||||||||
| 125 | # given: synopsis; | ||||||||||
| 126 | |||||||||||
| 127 | my $result = $example->result('fail'); | ||||||||||
| 128 | |||||||||||
| 129 | # bless(..., "Venus::Result") | ||||||||||
| 130 | |||||||||||
| 131 | =back | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||
| 134 | |||||||||||
| 135 | =head1 AUTHORS | ||||||||||
| 136 | |||||||||||
| 137 | Awncorp, C<awncorp@cpan.org> | ||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | =head1 LICENSE | ||||||||||
| 142 | |||||||||||
| 143 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||
| 144 | |||||||||||
| 145 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 146 | the terms of the Apache license version 2.0. | ||||||||||
| 147 | |||||||||||
| 148 | =cut | ||||||||||