blib/lib/Venus/Role/Deferrable.pm

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