| 1 | package Venus::Role::Deferrable; | ||||||||||
| 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 'fault'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | # METHODS | ||||||||||
| 13 | |||||||||||
| 14 | 18 | ▶ | sub defer { | ||||||||
|
Subroutine
defer: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 15 | 18 | my ($self, $name, @args) = @_; | |||||||||
| 16 | |||||||||||
| 17 | 18 | ▶ | return sub {$self} if !$name; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 17 | ▶ | my $code = $self->can($name) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | or fault "Unable to defer $name: can't find $name in @{[ref $self]}"; | |||||||||
| 21 | |||||||||||
| 22 | 17 | ▶ | return sub {@_ = ($self, @args, @_); goto $code}; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | # EXPORTS | ||||||||||
| 26 | |||||||||||
| 27 | 123 | ▶ | sub EXPORT { | ||||||||
|
Subroutine
EXPORT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 28 | 123 | ['defer'] | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 119 | 1; | |||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | |||||||||||
| 35 | =head1 NAME | ||||||||||
| 36 | |||||||||||
| 37 | Venus::Role::Deferrable - Deferrable Role | ||||||||||
| 38 | |||||||||||
| 39 | =cut | ||||||||||
| 40 | |||||||||||
| 41 | =head1 ABSTRACT | ||||||||||
| 42 | |||||||||||
| 43 | Deferrable Role for Perl 5 | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | =head1 SYNOPSIS | ||||||||||
| 48 | |||||||||||
| 49 | package Example; | ||||||||||
| 50 | |||||||||||
| 51 | use Venus::Class; | ||||||||||
| 52 | |||||||||||
| 53 | with 'Venus::Role::Deferrable'; | ||||||||||
| 54 | |||||||||||
| 55 | sub test { | ||||||||||
| 56 | my ($self, @args) = @_; | ||||||||||
| 57 | |||||||||||
| 58 | return $self->okay(@args); | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub okay { | ||||||||||
| 62 | my ($self, @args) = @_; | ||||||||||
| 63 | |||||||||||
| 64 | return [@args]; | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | package main; | ||||||||||
| 68 | |||||||||||
| 69 | my $example = Example->new; | ||||||||||
| 70 | |||||||||||
| 71 | # my $code = $example->defer('test'); | ||||||||||
| 72 | |||||||||||
| 73 | # sub {...} | ||||||||||
| 74 | |||||||||||
| 75 | # $code->(); | ||||||||||
| 76 | |||||||||||
| 77 | # [...] | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | =head1 DESCRIPTION | ||||||||||
| 82 | |||||||||||
| 83 | This package provides a mechanism for returning callbacks (i.e. closures) that | ||||||||||
| 84 | dispatches method calls. | ||||||||||
| 85 | |||||||||||
| 86 | =cut | ||||||||||
| 87 | |||||||||||
| 88 | =head1 METHODS | ||||||||||
| 89 | |||||||||||
| 90 | This package provides the following methods: | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | =head2 defer | ||||||||||
| 95 | |||||||||||
| 96 | defer(string $method, any @args) (coderef) | ||||||||||
| 97 | |||||||||||
| 98 | The defer method returns the named method as a callback (i.e. closure) which | ||||||||||
| 99 | dispatches to the method call specified. | ||||||||||
| 100 | |||||||||||
| 101 | I<Since C<1.80>> | ||||||||||
| 102 | |||||||||||
| 103 | =over 4 | ||||||||||
| 104 | |||||||||||
| 105 | =item defer example 1 | ||||||||||
| 106 | |||||||||||
| 107 | # given: synopsis | ||||||||||
| 108 | |||||||||||
| 109 | package main; | ||||||||||
| 110 | |||||||||||
| 111 | $example = Example->new; | ||||||||||
| 112 | |||||||||||
| 113 | # bless({}, 'Example') | ||||||||||
| 114 | |||||||||||
| 115 | # my $result = $example->defer('test', 1..4); | ||||||||||
| 116 | |||||||||||
| 117 | # $result->(); | ||||||||||
| 118 | |||||||||||
| 119 | # [1..4] | ||||||||||
| 120 | |||||||||||
| 121 | =back | ||||||||||
| 122 | |||||||||||
| 123 | =over 4 | ||||||||||
| 124 | |||||||||||
| 125 | =item defer example 2 | ||||||||||
| 126 | |||||||||||
| 127 | # given: synopsis | ||||||||||
| 128 | |||||||||||
| 129 | package main; | ||||||||||
| 130 | |||||||||||
| 131 | $example = Example->new; | ||||||||||
| 132 | |||||||||||
| 133 | # bless({}, 'Example') | ||||||||||
| 134 | |||||||||||
| 135 | # my $result = $example->defer('test', 1..4); | ||||||||||
| 136 | |||||||||||
| 137 | # $result->(1..4); | ||||||||||
| 138 | |||||||||||
| 139 | # [1..4, 1..4] | ||||||||||
| 140 | |||||||||||
| 141 | =back | ||||||||||
| 142 | |||||||||||
| 143 | =over 4 | ||||||||||
| 144 | |||||||||||
| 145 | =item defer example 3 | ||||||||||
| 146 | |||||||||||
| 147 | # given: synopsis | ||||||||||
| 148 | |||||||||||
| 149 | package main; | ||||||||||
| 150 | |||||||||||
| 151 | $example = Example->new; | ||||||||||
| 152 | |||||||||||
| 153 | # bless({}, 'Example') | ||||||||||
| 154 | |||||||||||
| 155 | # my $result = $example->defer; | ||||||||||
| 156 | |||||||||||
| 157 | # $result->(); | ||||||||||
| 158 | |||||||||||
| 159 | # bless({}, 'Example') | ||||||||||
| 160 | |||||||||||
| 161 | =back | ||||||||||
| 162 | |||||||||||
| 163 | =cut | ||||||||||
| 164 | |||||||||||
| 165 | =head1 AUTHORS | ||||||||||
| 166 | |||||||||||
| 167 | Awncorp, C<awncorp@cpan.org> | ||||||||||
| 168 | |||||||||||
| 169 | =cut | ||||||||||
| 170 | |||||||||||
| 171 | =head1 LICENSE | ||||||||||
| 172 | |||||||||||
| 173 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||
| 174 | |||||||||||
| 175 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 176 | the terms of the Apache license version 2.0. | ||||||||||
| 177 | |||||||||||
| 178 | =cut | ||||||||||