blib/lib/Venus/Factory.pm

filter: Statementstmt 91.5% 291 / 318 Branchbran 73.1% 139 / 190 Conditioncond 53.6% 37 / 69 MC/DCmcdc 21.0% 8 / 38 Subroutinesub 97.3% 36 / 37 Podpod 90.6% 29 / 32 totaltotal 78.9% 540 / 684 CC 125 SCAR 32.8
CC
125
Cov
81%
resolve
92.4
args
30.5
extend
18.7
CRAP 26.5
« blib/lib/Venus/Config.pm ↑ Summary blib/lib/Venus/Assert.pm »
1 package Venus::Factory;
2  
3 2 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 2 ▶use Venus::Class 'attr', 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 2 base 'Venus::Kind::Utility';
15  
16 # INTEGRATES
17  
18 2 with 'Venus::Role::Buildable';
19 2 with 'Venus::Role::Encaseable';
20 2 with 'Venus::Role::Tryable';
21 2 with 'Venus::Role::Catchable';
22 2 with 'Venus::Role::Throwable';
23  
24 # ATTRIBUTES
25  
26 2 attr 'name';
27  
28 # METHODS
29  
30 31 ▶sub args {
Subroutine args: called CC=22 SCAR=34.2
Pod documented
31 31 my ($self, @args) = @_;
32  
33 31 my @value = $self->value;
34  
35 31 ▶ @value = @args if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 12 19 31
36  
37 31 my @list = $self->list;
38  
39 31 for my $item (reverse @list) {
40 0 ▶ my ($name, @args) = ref $item ? @{$item} : $item;
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 0 5 5
41 5 my $container = $self->retrieve($name);
42 5 ▶ unshift @value, $container->resolve(@args) if $container;
Branch: 1 branch
BranchTrueFalseTotal
if $container 5 0 5
43 }
44  
45 31 ▶ return @value if @value > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @value > 1 4 27 31
46  
47 27 my $arrayref = $self->arrayref;
48  
49 27 ▶ if ($arrayref && (!@value || (@value == 1 && ref $value[0] eq 'ARRAY'))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arrayref and !@value || @value == 1 && ref $value[0] eq "ARRAY") 2 25 27
Condition55%5/9
$arrayref and !@value || @value == 1 && ref $value[0] eq "ARRAY"
!ll&&!rl&&r
2502
not @value or @value == 1 and ref $value[0] eq "ARRAY"
l!l&&r!l&&!r
110
@value == 1 and ref $value[0] eq "ARRAY"
!ll&&!rl&&r
001
MC/DC25%1/4
$arrayref and !@value || @value == 1 && ref $value[0] eq "ARRAY"
$arrayref not @value @value == 1 ref $value[0] eq "ARRAY"
Truth table60%3/5
A and not(B) or C and D
A= $arrayrefB= not @valueC= @value == 1D= ref $value[0] eq "ARRAY"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
50 2 for my $item (reverse @{$arrayref}) {
51 0 ▶ my ($name, @args) = ref $item ? @{$item} : $item;
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 0 4 4
52 4 my $container = $self->retrieve($name);
53 4 ▶ unshift @{$value[0]}, $container->resolve(@args) if $container;
Branch: 1 branch
BranchTrueFalseTotal
if $container 4 0 4
54 }
55 }
56  
57 27 my $hashref = $self->hashref;
58  
59 27 ▶ if ($hashref && (!@value || (@value == 1 && ref $value[0] eq 'HASH'))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hashref and !@value || @value == 1 && ref $value[0] eq "HASH") 2 25 27
Condition55%5/9
$hashref and !@value || @value == 1 && ref $value[0] eq "HASH"
!ll&&!rl&&r
2502
not @value or @value == 1 and ref $value[0] eq "HASH"
l!l&&r!l&&!r
110
@value == 1 and ref $value[0] eq "HASH"
!ll&&!rl&&r
001
MC/DC25%1/4
$hashref and !@value || @value == 1 && ref $value[0] eq "HASH"
$hashref not @value @value == 1 ref $value[0] eq "HASH"
Truth table60%3/5
A and not(B) or C and D
A= $hashrefB= not @valueC= @value == 1D= ref $value[0] eq "HASH"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
60 2 for my $pair (map +([$_, $$hashref{$_}]), keys %{$hashref}) {
61 0 ▶ my ($name, @args) = ref $$pair[1] ? @{$$pair[1]} : $$pair[1];
Branch: 1 branch
BranchTrueFalseTotal
ref $pair->[1] ? : 0 4 4
62 4 my $container = $self->retrieve($name);
63 4 ▶ ${$value[0]}{$$pair[0]} = $container->resolve(@args) if $container && !exists ${$value[0]}{$$pair[0]};
Branch: 1 branch
BranchTrueFalseTotal
if $container and not exists ${$value[0];}{$pair->[0]} 4 0 4
Condition33%1/3
$container and not exists ${$value[0];}{$pair->[0]}
!ll&&!rl&&r
004
MC/DC0%0/2
$container and not exists ${$value[0];}{$pair->[0]}
$container not exists ${$value[0];}{$pair->[0]}
Truth table33%1/3
A and not(B)
A= $containerB= not exists ${$value[0];}{$pair->[0]}
ABresult
0X0
100
111
64 }
65 }
66  
67 27 ▶ return wantarray ? (@value) : $value[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 19 8 27
68 }
69  
70 44 ▶sub arrayref {
Subroutine arrayref: called CC=2 SCAR=6.9
Pod documented
71 44 my ($self, @data) = @_;
72  
73 44 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 5 39 44
74 5 $self->{arrayref} = [@data];
75  
76 5 return $self;
77 }
78 else {
79  
80 39 return $self->{arrayref};
81 }
82 }
83  
84 70 ▶sub assert {
Subroutine assert: called CC=2 SCAR=6.9
Pod documented
85 70 my ($self, @data) = @_;
86  
87 70 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 41 29 70
88 41 $self->{assert} = $data[0];
89  
90 41 return $self;
91 }
92 else {
93  
94 29 return $self->{assert};
95 }
96 }
97  
98 2 ▶sub attach {
Subroutine attach: called CC=6 SCAR=18.7
Pod documented
99 2 my ($self, $name, $data) = @_;
100  
101 2 my $class = ref $self;
102  
103 2 ▶ return $self if !$data || !UNIVERSAL::isa($data, $class);
Branch: 1 branch
BranchTrueFalseTotal
unless $data and UNIVERSAL::isa($data, $class) 1 1 2
Condition66%2/3
$data and UNIVERSAL::isa($data, $class)
!ll&&!rl&&r
101
MC/DC50%1/2
$data and UNIVERSAL::isa($data, $class)
$data UNIVERSAL::isa($data, $class)
Truth table66%2/3
A and B
A= $dataB= UNIVERSAL::isa($data, $class)
ABresult
0X0
100
111
104  
105 1 ▶ my $registry = $self->registry || $self->registry({})->registry;
Condition33%1/3
$self->registry || $self->registry({})->registry
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->registry || $self->registry({})->registry
$self->registry $self->registry({})->registry
Truth table33%1/3
A || B
A= $self->registryB= $self->registry({})->registry
ABresult
1X1
011
000
106  
107 1 my $container = $registry->{$name} = $data;
108  
109 1 $container->registry($registry);
110  
111 1 ▶ $container->name($name) if !$container->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $container->name 1 0 1
112  
113 1 ▶ $container->cache($self->cache) if $self->cache;
Branch: 1 branch
BranchTrueFalseTotal
if $self->cache 0 1 1
114  
115 1 return $container;
116 }
117  
118 5 ▶sub build {
Subroutine build: called CC=1 SCAR=0.0
Pod documented
119 5 my ($self, $name, @args) = @_;
120  
121 5 my $container = $self->retrieve($name);
122  
123 5 return $container->resolve(@args);
124 }
125  
126 37 ▶sub builder {
Subroutine builder: called CC=2 SCAR=6.9
Pod documented
127 37 my ($self, @data) = @_;
128  
129 37 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 8 29 37
130 8 $self->{builder} = $data[0];
131  
132 8 return $self;
133 }
134 else {
135  
136 29 return $self->{builder};
137 }
138 }
139  
140 84 ▶sub cache {
Subroutine cache: called CC=2 SCAR=6.9
Pod documented
141 84 my ($self, @data) = @_;
142  
143 84 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 4 80 84
144 4 $self->recase('cache', $data[0]);
145  
146 4 return $self;
147 }
148 else {
149  
150 80 return $self->encased('cache');
151 }
152 }
153  
154 53 ▶sub cached {
Subroutine cached: called CC=3 SCAR=11.0
Pod documented
155 53 my ($self, @data) = @_;
156  
157 53 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 3 50 53
158 3 ▶ $self->{cached} = $data[0] ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$data[0] ? : 3 0 3
159  
160 3 return $self;
161 }
162 else {
163  
164 50 return $self->{cached};
165 }
166 }
167  
168 2 ▶sub callback {
Subroutine callback: called CC=1 SCAR=0.0
Pod documented
169 2 my ($self, @args) = @_;
170  
171 2 return $self->defer('resolve', @args);
172 }
173  
174 35 ▶sub chain {
Subroutine chain: called CC=2 SCAR=6.9
Pod documented
175 35 my ($self, @data) = @_;
176  
177 35 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 4 31 35
178 4 $self->{chain} = [@data];
179  
180 4 return $self;
181 }
182 else {
183  
184 31 return $self->{chain};
185 }
186 }
187  
188 33 ▶sub class {
Subroutine class: called CC=6 SCAR=18.2
Pod documented
189 33 my ($self, @data) = @_;
190  
191 33 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 31 2 33
192 31 $self->assert($data[0])->package($data[0])->method('new');
193  
194 31 return $self;
195 }
196 else {
197  
198 2 ▶ return ($self->protocol
Branch: 1 branch
BranchTrueFalseTotal
$self->protocol && $self->protocol eq 'method' && $self->dispatch && $self->dispatch eq 'new' ? : 1 1 2
Condition66%6/9
$self->protocol and $self->protocol eq "method" and $self->dispatch and $self->dispatch eq "new"
!ll&&!rl&&r
101
$self->protocol and $self->protocol eq "method" and $self->dispatch
!ll&&!rl&&r
101
$self->protocol and $self->protocol eq "method"
!ll&&!rl&&r
101
MC/DC25%1/4
$self->protocol and $self->protocol eq "method" and $self->dispatch and $self->dispatch eq "new"
$self->protocol $self->protocol eq "method" $self->dispatch $self->dispatch eq "new"
Truth table40%2/5
A and B and C and D
A= $self->protocolB= $self->protocol eq "method"C= $self->dispatchD= $self->dispatch eq "new"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
199 && $self->protocol eq 'method'
200 && $self->dispatch
201 && $self->dispatch eq 'new') ? $self->package : undef;
202 }
203 }
204  
205 6 ▶sub clone {
Subroutine clone: called CC=16 SCAR=28.6
Pod documented
206 6 my ($self) = @_;
207  
208 6 require Venus;
209  
210 6 my $class = ref $self;
211  
212 6 my $container = $class->new;
213  
214 6 my $arrayref = $self->arrayref;
215  
216 6 ▶ $container->arrayref(Venus::clone($arrayref)) if defined $arrayref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $arrayref 0 6 6
217  
218 6 my $assert = $self->assert;
219  
220 6 ▶ $container->assert($assert) if defined $assert;
Branch: 1 branch
BranchTrueFalseTotal
if defined $assert 4 2 6
221  
222 6 my $builder = $self->builder;
223  
224 6 ▶ $container->builder($builder) if defined $builder;
Branch: 1 branch
BranchTrueFalseTotal
if defined $builder 2 4 6
225  
226 6 my $cached = $self->cached;
227  
228 6 ▶ $container->cached($cached) if defined $cached;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cached 0 6 6
229  
230 6 my $chain = $self->chain;
231  
232 6 ▶ $container->chain(Venus::clone($chain)) if defined $chain;
Branch: 1 branch
BranchTrueFalseTotal
if defined $chain 0 6 6
233  
234 6 my $constructor = $self->constructor;
235  
236 6 ▶ $container->constructor($constructor) if defined $constructor;
Branch: 1 branch
BranchTrueFalseTotal
if defined $constructor 0 6 6
237  
238 6 my $dispatch = $self->dispatch;
239  
240 6 ▶ $container->dispatch($dispatch) if defined $dispatch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dispatch 4 2 6
241  
242 6 my $hashref = $self->hashref;
243  
244 6 ▶ $container->hashref(Venus::clone($hashref)) if defined $hashref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hashref 0 6 6
245  
246 6 my @list = $self->list;
247  
248 6 ▶ $container->list(map ref $_ ? Venus::clone($_) : $_, @list) if @list;
Branch: 2 branches
BranchTrueFalseTotal
if @list 0 6 6
ref $_ ? : 0 0 0
249  
250 6 my $name = $self->name;
251  
252 6 ▶ $container->name($name) if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 4 2 6
253  
254 6 my $package = $self->package;
255  
256 6 ▶ $container->package($package) if defined $package;
Branch: 1 branch
BranchTrueFalseTotal
if defined $package 4 2 6
257  
258 6 my $protocol = $self->protocol;
259  
260 6 ▶ $container->protocol($protocol) if defined $protocol;
Branch: 1 branch
BranchTrueFalseTotal
if defined $protocol 4 2 6
261  
262 6 my @value = $self->value;
263  
264 6 ▶ $container->value(map ref $_ ? Venus::clone($_) : $_, @value) if @value;
Branch: 2 branches
BranchTrueFalseTotal
if @value 0 6 6
ref $_ ? : 0 0 0
265  
266 6 return $container;
267 }
268  
269 32 ▶sub constructor {
Subroutine constructor: called CC=2 SCAR=6.9
Pod documented
270 32 my ($self, @data) = @_;
271  
272 32 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 3 29 32
273 3 $self->{constructor} = $data[0];
274  
275 3 return $self;
276 }
277 else {
278  
279 29 return $self->{constructor};
280 }
281 }
282  
283 2 ▶sub detach {
Subroutine detach: called CC=3 SCAR=11.0
Pod documented
284 2 my ($self, $name) = @_;
285  
286 2 ▶ my $registry = $self->registry || $self->registry({})->registry;
Condition66%2/3
$self->registry || $self->registry({})->registry
l!l&&r!l&&!r
110
MC/DC0%0/2
$self->registry || $self->registry({})->registry
$self->registry $self->registry({})->registry
Truth table66%2/3
A || B
A= $self->registryB= $self->registry({})->registry
ABresult
1X1
011
000
287  
288 2 my $container = delete $registry->{$name};
289  
290 2 ▶ return undef if !$container;
Branch: 1 branch
BranchTrueFalseTotal
unless $container 1 1 2
291  
292 1 return $container;
293 }
294  
295 81 ▶sub dispatch {
Subroutine dispatch: called CC=2 SCAR=6.9
Pod documented
296 81 my ($self, @data) = @_;
297  
298 81 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 47 34 81
299 47 $self->{dispatch} = $data[0];
300  
301 47 return $self;
302 }
303 else {
304  
305 34 return $self->{dispatch};
306 }
307 }
308  
309 2 ▶sub dispatch_to_function {
Subroutine dispatch_to_function: called CC=1 SCAR=0.0
Pod undocumented
310 2 my ($self, $invocant, $function, @args) = @_;
311  
312 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
313  
314 2 return &{"${invocant}::${function}"}(@args);
315 }
316  
317 16 ▶sub dispatch_to_method {
Subroutine dispatch_to_method: called CC=1 SCAR=0.0
Pod undocumented
318 16 my ($self, $invocant, $method, @args) = @_;
319  
320 16 return $invocant->$method(@args);
321 }
322  
323 0 ▶sub dispatch_to_routine {
Subroutine dispatch_to_routine: not called CC=2 SCAR=17.9
Pod undocumented
324 0 my ($self, $invocant, $routine, @args) = @_;
325  
326 0 ▶ return (ref $invocant || $invocant)->$routine(@args);
Condition0%0/3
ref $invocant || $invocant
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table0%0/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
327 }
328  
329 2 ▶sub extend {
Subroutine extend: called CC=16 SCAR=29.3
Pod documented
330 2 my ($self, $name) = @_;
331  
332 2 require Venus;
333  
334 2 my $container = $self->retrieve($name);
335  
336 2 ▶ return $self if !$container;
Branch: 1 branch
BranchTrueFalseTotal
unless $container 0 2 2
337  
338 2 my $arrayref = $container->arrayref;
339  
340 2 ▶ $self->arrayref(Venus::clone($arrayref)) if defined $arrayref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $arrayref 0 2 2
341  
342 2 my $assert = $container->assert;
343  
344 2 ▶ $self->assert($assert) if defined $assert;
Branch: 1 branch
BranchTrueFalseTotal
if defined $assert 1 1 2
345  
346 2 my $builder = $container->builder;
347  
348 2 ▶ $self->builder($builder) if defined $builder;
Branch: 1 branch
BranchTrueFalseTotal
if defined $builder 0 2 2
349  
350 2 my $cached = $container->cached;
351  
352 2 ▶ $self->cached($cached) if defined $cached;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cached 0 2 2
353  
354 2 my $chain = $container->chain;
355  
356 2 ▶ $self->chain(Venus::clone($chain)) if defined $chain;
Branch: 1 branch
BranchTrueFalseTotal
if defined $chain 0 2 2
357  
358 2 my $constructor = $container->constructor;
359  
360 2 ▶ $self->constructor($constructor) if defined $constructor;
Branch: 1 branch
BranchTrueFalseTotal
if defined $constructor 0 2 2
361  
362 2 my $dispatch = $container->dispatch;
363  
364 2 ▶ $self->dispatch($dispatch) if defined $dispatch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dispatch 1 1 2
365  
366 2 my $hashref = $container->hashref;
367  
368 2 ▶ $self->hashref(Venus::clone($hashref)) if defined $hashref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $hashref 0 2 2
369  
370 2 my @list = $container->list;
371  
372 2 ▶ $self->list(map ref $_ ? Venus::clone($_) : $_, @list) if @list;
Branch: 2 branches
BranchTrueFalseTotal
if @list 0 2 2
ref $_ ? : 0 0 0
373  
374 2 my $package = $container->package;
375  
376 2 ▶ $self->package($package) if defined $package;
Branch: 1 branch
BranchTrueFalseTotal
if defined $package 1 1 2
377  
378 2 my $protocol = $container->protocol;
379  
380 2 ▶ $self->protocol($protocol) if defined $protocol;
Branch: 1 branch
BranchTrueFalseTotal
if defined $protocol 1 1 2
381  
382 2 my @value = $container->value;
383  
384 2 ▶ $self->value(map ref $_ ? Venus::clone($_) : $_, @value) if @value;
Branch: 2 branches
BranchTrueFalseTotal
if @value 0 2 2
ref $_ ? : 0 0 0
385  
386 2 return $self;
387 }
388  
389 7 ▶sub function {
Subroutine function: called CC=4 SCAR=13.9
Pod documented
390 7 my ($self, @data) = @_;
391  
392 7 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 5 2 7
393 5 $self->protocol('function')->dispatch($data[0]);
394  
395 5 return $self;
396 }
397 else {
398  
399 2 ▶ return ($self->protocol && $self->protocol eq 'function') ? $self->dispatch : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->protocol && $self->protocol eq 'function' ? : 1 1 2
Condition66%2/3
$self->protocol and $self->protocol eq "function"
!ll&&!rl&&r
101
MC/DC50%1/2
$self->protocol and $self->protocol eq "function"
$self->protocol $self->protocol eq "function"
Truth table66%2/3
A and B
A= $self->protocolB= $self->protocol eq "function"
ABresult
0X0
100
111
400 }
401 }
402  
403 43 ▶sub hashref {
Subroutine hashref: called CC=2 SCAR=6.9
Pod documented
404 43 my ($self, @data) = @_;
405  
406 43 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 5 38 43
407 5 $self->{hashref} = $data[0];
408  
409 5 return $self;
410 }
411 else {
412  
413 38 return $self->{hashref};
414 }
415 }
416  
417 48 ▶sub list {
Subroutine list: called CC=3 SCAR=11.0
Pod documented
418 48 my ($self, @data) = @_;
419  
420 48 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 6 42 48
421 6 $self->{list} = [@data];
422  
423 6 return $self;
424 }
425 else {
426  
427 42 ▶ return $self->{list} ? @{$self->{list}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'list'} ? : 5 37 42
428 }
429 }
430  
431 35 ▶sub method {
Subroutine method: called CC=4 SCAR=13.9
Pod documented
432 35 my ($self, @data) = @_;
433  
434 35 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 33 2 35
435 33 $self->protocol('method')->dispatch($data[0]);
436  
437 33 return $self;
438 }
439 else {
440  
441 2 ▶ return ($self->protocol && $self->protocol eq 'method') ? $self->dispatch : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->protocol && $self->protocol eq 'method' ? : 1 1 2
Condition66%2/3
$self->protocol and $self->protocol eq "method"
!ll&&!rl&&r
101
MC/DC50%1/2
$self->protocol and $self->protocol eq "method"
$self->protocol $self->protocol eq "method"
Truth table66%2/3
A and B
A= $self->protocolB= $self->protocol eq "method"
ABresult
0X0
100
111
442 }
443 }
444  
445 88 ▶sub package {
Subroutine package: called CC=2 SCAR=6.9
Pod documented
446 88 my ($self, @data) = @_;
447  
448 88 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 41 47 88
449 41 $self->{package} = $data[0];
450  
451 41 return $self;
452 }
453 else {
454  
455 47 return $self->{package};
456 }
457 }
458  
459 88 ▶sub protocol {
Subroutine protocol: called CC=2 SCAR=6.9
Pod documented
460 88 my ($self, @data) = @_;
461  
462 88 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 47 41 88
463 47 $self->{protocol} = $data[0];
464  
465 47 return $self;
466 }
467 else {
468  
469 41 return $self->{protocol};
470 }
471 }
472  
473 36 ▶sub register {
Subroutine register: called CC=3 SCAR=11.0
Pod documented
474 36 my ($self, $name) = @_;
475  
476 36 my $class = ref $self;
477  
478 36 ▶ my $registry = $self->registry || $self->registry({})->registry;
Condition66%2/3
$self->registry || $self->registry({})->registry
l!l&&r!l&&!r
8280
MC/DC0%0/2
$self->registry || $self->registry({})->registry
$self->registry $self->registry({})->registry
Truth table66%2/3
A || B
A= $self->registryB= $self->registry({})->registry
ABresult
1X1
011
000
479  
480 36 my $container = $registry->{$name} = $class->new(name => $name);
481  
482 36 $container->registry($registry);
483  
484 36 ▶ $container->cache($self->cache) if $self->cache;
Branch: 1 branch
BranchTrueFalseTotal
if $self->cache 1 35 36
485  
486 36 return $container;
487 }
488  
489 169 ▶sub registry {
Subroutine registry: called CC=2 SCAR=6.9
Pod documented
490 169 my ($self, @data) = @_;
491  
492 169 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 69 100 169
493 69 $self->recase('registry', $data[0]);
494  
495 69 return $self;
496 }
497 else {
498  
499 100 return $self->encased('registry');
500 }
501 }
502  
503 8 ▶sub reset {
Subroutine reset: called CC=2 SCAR=6.9
Pod documented
504 8 my ($self, @data) = @_;
505  
506 8 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 6 2 8
507 6 my $value = delete $self->{$data[0]};
508  
509 6 return $value;
510 }
511 else {
512  
513 2 delete $self->{arrayref};
514 2 delete $self->{assert};
515 2 delete $self->{builder};
516 2 delete $self->{cached};
517 2 delete $self->{callback};
518 2 delete $self->{chain};
519 2 delete $self->{constructor};
520 2 delete $self->{dispatch};
521 2 delete $self->{hashref};
522 2 delete $self->{list};
523 2 delete $self->{name};
524 2 delete $self->{package};
525 2 delete $self->{protocol};
526 2 delete $self->{value};
527  
528 2 return $self;
529 }
530 }
531  
532 40 ▶sub resolve {
Subroutine resolve: called CC=30 SCAR=45.3
Pod documented
533 40 my ($self, @args) = @_;
534  
535 40 my ($cache, $cached) = ($self->cache, $self->cached);
536  
537 40 ▶ return $cache->{$self->name} if $cache && $cached && $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $cache and $cached and $self->name 4 36 40
Condition66%4/6
$cache and $cached and $self->name
!ll&&!rl&&r
3604
$cache and $cached
!ll&&!rl&&r
3604
MC/DC33%1/3
$cache and $cached and $self->name
$cache $cached $self->name
Truth table50%2/4
A and B and C
A= $cacheB= $cachedC= $self->name
ABCresult
0XX0
10X0
1100
1111
538  
539 36 require Venus::Space;
540  
541 36 my $package = $self->package;
542  
543 36 ▶ return (scalar $self->value) ? (wantarray ? ($self->value) : ($self->value)[0]) : () if !$package;
Branch: 3 branches
BranchTrueFalseTotal
unless $package 17 19 36
scalar $self->value ? : 14 3 17
wantarray ? : 9 5 14
544  
545 19 Venus::Space->new($package)->tryload;
546  
547 19 my $protocol = $self->protocol;
548  
549 19 my $dispatch = $self->dispatch;
550  
551 19 my @result;
552  
553 19 ▶ if ($protocol eq 'function') {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol eq "function") 2 17 19
554 2 my $constructor = $self->constructor;
555  
556 2 ▶ if ($constructor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constructor) { } 0 2 2
557 0 @result = $self->$constructor($package, $dispatch, $self->args(@args));
558 }
559 else {
560 2 @result = $self->dispatch_to_function($package, $dispatch, $self->args(@args));
561 }
562  
563 2 my $chain = $self->chain;
564  
565 2 ▶ if ($chain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chain) 0 2 2
566 0 for my $item (@{$chain}) {
567 0 ▶ my ($name, @args) = ref $item ? @{$item} : $item;
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 0 0 0
568 0 ▶ @result = $self->dispatch_to_function($package, $name, @result ? @result : @args);
Branch: 1 branch
BranchTrueFalseTotal
@result ? : 0 0 0
569 }
570 }
571 }
572  
573 19 ▶ if ($protocol eq 'method') {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol eq "method") 17 2 19
574 17 my $constructor = $self->constructor;
575  
576 17 ▶ if ($constructor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constructor) { } 1 16 17
577 1 @result = (scalar $self->$constructor($package, $dispatch, $self->args(@args)));
578 }
579 else {
580 16 @result = (scalar $self->dispatch_to_method($package, $dispatch, $self->args(@args)));
581 }
582  
583 17 my $chain = $self->chain;
584  
585 17 ▶ if ($chain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chain) 0 17 17
586 0 for my $item (@{$chain}) {
587 0 ▶ my ($name, @args) = ref $item ? @{$item} : $item;
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 0 0 0
588 0 @result = (scalar $result[0]->$name(@args));
589 }
590 }
591 }
592  
593 19 ▶ if ($protocol eq 'routine') {
Branch: 1 branch
BranchTrueFalseTotal
if ($protocol eq "routine") 0 19 19
594 0 my $constructor = $self->constructor;
595  
596 0 ▶ if ($constructor) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constructor) { } 0 0 0
597 0 @result = (scalar $self->$constructor($package, $dispatch, $self->args(@args)));
598 }
599 else {
600 0 @result = (scalar $self->dispatch_to_method($package, $dispatch, $self->args(@args)));
601 }
602  
603 0 my $chain = $self->chain;
604  
605 0 ▶ if ($chain) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chain) 0 0 0
606 0 for my $item (@{$chain}) {
607 0 ▶ my ($name, @args) = ref $item ? @{$item} : $item;
Branch: 1 branch
BranchTrueFalseTotal
ref $item ? : 0 0 0
608 0 @result = (scalar $result[0]->$name(@args));
609 }
610 }
611 }
612  
613 19 my $builder = $self->builder;
614  
615 19 local $_ = $result[0];
616  
617 19 ▶ @result = ($self->$builder(@result)) if $builder;
Branch: 1 branch
BranchTrueFalseTotal
if $builder 3 16 19
618  
619 19 ▶ if (@result == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@result == 1) 19 0 19
620 19 my $assert = $self->assert;
621  
622 19 ▶ if ($assert) {
Branch: 1 branch
BranchTrueFalseTotal
if ($assert) 17 2 19
623 17 require Venus::Assert;
624  
625 17 Venus::Assert->new($assert)->accept($assert)->result($result[0]);
626 }
627  
628 19 ▶ $cache->{$self->name} = $result[0] if $cache && $cached && $self->name
Branch: 1 branch
BranchTrueFalseTotal
if $cache and $cached and $self->name 0 19 19
Condition33%2/6
$cache and $cached and $self->name
!ll&&!rl&&r
1900
$cache and $cached
!ll&&!rl&&r
1900
MC/DC0%0/3
$cache and $cached and $self->name
$cache $cached $self->name
Truth table25%1/4
A and B and C
A= $cacheB= $cachedC= $self->name
ABCresult
0XX0
10X0
1100
1111
629 }
630  
631 19 ▶ return wantarray ? (@result) : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 18 19
632 }
633  
634 23 ▶sub retrieve {
Subroutine retrieve: called CC=3 SCAR=11.2
Pod documented
635 23 my ($self, $name) = @_;
636  
637 23 ▶ return $self if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 5 18 23
638  
639 18 my $class = ref $self;
640  
641 18 ▶ my $registry = $self->registry || $self->registry({})->registry;
Condition33%1/3
$self->registry || $self->registry({})->registry
l!l&&r!l&&!r
1800
MC/DC0%0/2
$self->registry || $self->registry({})->registry
$self->registry $self->registry({})->registry
Truth table33%1/3
A || B
A= $self->registryB= $self->registry({})->registry
ABresult
1X1
011
000
642  
643 18 my $container = $registry->{$name};
644  
645 18 return $container;
646 }
647  
648 4 ▶sub routine {
Subroutine routine: called CC=4 SCAR=13.9
Pod documented
649 4 my ($self, @data) = @_;
650  
651 4 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 2 2 4
652 2 $self->protocol('routine')->dispatch($data[0]);
653  
654 2 return $self;
655 }
656 else {
657  
658 2 ▶ return ($self->protocol && $self->protocol eq 'routine') ? $self->dispatch : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->protocol && $self->protocol eq 'routine' ? : 1 1 2
Condition66%2/3
$self->protocol and $self->protocol eq "routine"
!ll&&!rl&&r
101
MC/DC50%1/2
$self->protocol and $self->protocol eq "routine"
$self->protocol $self->protocol eq "routine"
Truth table66%2/3
A and B
A= $self->protocolB= $self->protocol eq "routine"
ABresult
0X0
100
111
659 }
660 }
661  
662 99 ▶sub value {
Subroutine value: called CC=3 SCAR=11.0
Pod documented
663 99 my ($self, @data) = @_;
664  
665 99 ▶ if (@data) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data) { } 25 74 99
666 25 $self->{value} = [@data];
667  
668 25 return $self;
669 }
670 else {
671  
672 74 ▶ return $self->{value} ? @{$self->{value}} : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'value'} ? : 39 35 74
673 }
674 }
675  
676 2 1;
677  
678  
679  
680 =head1 NAME
681  
682 Venus::Factory - Factory Class
683  
684 =cut
685  
686 =head1 ABSTRACT
687  
688 Factory Class for Perl 5
689  
690 =cut
691  
692 =head1 SYNOPSIS
693  
694 package main;
695  
696 use Venus::Factory;
697  
698 my $factory = Venus::Factory->new;
699  
700 # $factory->class('Venus::Path');
701  
702 # $factory->build;
703  
704 # bless(.., "Venus::Path")
705  
706 =cut
707  
708 =head1 DESCRIPTION
709  
710 This package provides an object-oriented factory pattern and mechanism for
711 building objects using dependency injection.
712  
713 =cut
714  
715 =head1 ATTRIBUTES
716  
717 This package has the following attributes:
718  
719 =cut
720  
721 =head2 name
722  
723 name(string $name) (string)
724  
725 The name attribute is read/write, accepts C<(string)> values, is optional, and
726 defaults to C<undef>.
727  
728 I<Since C<4.15>>
729  
730 =over 4
731  
732 =item name example 1
733  
734 # given: synopsis;
735  
736 my $name = $factory->name('log');
737  
738 # "log"
739  
740 =back
741  
742 =over 4
743  
744 =item name example 2
745  
746 # given: synopsis;
747  
748 # given: example-1 name
749  
750 $name = $factory->name;
751  
752 # "log"
753  
754 =back
755  
756 =cut
757  
758 =head1 INHERITS
759  
760 This package inherits behaviors from:
761  
762 L<Venus::Kind::Utility>
763  
764 =cut
765  
766 =head1 INTEGRATES
767  
768 This package integrates behaviors from:
769  
770 L<Venus::Role::Buildable>
771  
772 L<Venus::Role::Encaseable>
773  
774 L<Venus::Role::Tryable>
775  
776 L<Venus::Role::Catchable>
777  
778 L<Venus::Role::Throwable>
779  
780 =cut
781  
782 =head1 METHODS
783  
784 This package provides the following methods:
785  
786 =cut
787  
788 =head2 args
789  
790 args(any @args) (Any)
791  
792 The args method accepts arguments and merges them with any L</arrayref>,
793 L</hashref>, or L</list> registered in the current configuration and returns
794 the result. Returns a list in list context.
795  
796 =over 4
797  
798 =item * If an L</arrayref> exists and the argment is an arrayref, the values are
799 merged by appending the arguments provided to the end of the registered arrayref.
800  
801 =item * If a L</hashref> exists and the argment is a hashref, the values are
802 merged without overriding the keys and values from the registered hashref.
803  
804 =item * If a L</list> exists and the argment is a list of values, the values are
805 merged by appending the arguments provided to the end of the registered list.
806  
807 =back
808  
809 I<Since C<4.15>>
810  
811 =over 4
812  
813 =item args example 1
814  
815 # given: synopsis
816  
817 package main;
818  
819 my @args = $factory->args;
820  
821 # ()
822  
823 =back
824  
825 =over 4
826  
827 =item args example 2
828  
829 # given: synopsis
830  
831 package main;
832  
833 my $args = $factory->args;
834  
835 # undef
836  
837 =back
838  
839 =over 4
840  
841 =item args example 3
842  
843 # given: synopsis
844  
845 package main;
846  
847 my $args = $factory->args({path => '/root'});
848  
849 # {path => "/root"}
850  
851 =back
852  
853 =over 4
854  
855 =item args example 4
856  
857 # given: synopsis
858  
859 package main;
860  
861 $factory->value({path => '/boot'});
862  
863 my $args = $factory->args({path => '/root'});
864  
865 # {path => "/root"}
866  
867 =back
868  
869 =over 4
870  
871 =item args example 5
872  
873 # given: synopsis
874  
875 package main;
876  
877 $factory->value({path => '/boot'});
878  
879 my $args = $factory->args;
880  
881 # {path => "/boot"}
882  
883 =back
884  
885 =over 4
886  
887 =item args example 6
888  
889 # given: synopsis
890  
891 package main;
892  
893 $factory->value(name => 'example');
894  
895 my @args = $factory->args;
896  
897 # ('name', 'example')
898  
899 =back
900  
901 =over 4
902  
903 =item args example 7
904  
905 # given: synopsis
906  
907 package main;
908  
909 $factory->register('data.home')->value('/home');
910  
911 $factory->register('data.root')->value('/root');
912  
913 $factory->list('data.home', 'data.root');
914  
915 my @args = $factory->args;
916  
917 # ('/home', '/root')
918  
919 =back
920  
921 =over 4
922  
923 =item args example 8
924  
925 # given: synopsis
926  
927 package main;
928  
929 $factory->register('data.home')->value('/home');
930  
931 $factory->register('data.root')->value('/root');
932  
933 $factory->list('data.home', 'data.root');
934  
935 my @args = $factory->args('/boot');
936  
937 # ('/home', '/root', '/boot')
938  
939 =back
940  
941 =over 4
942  
943 =item args example 9
944  
945 # given: synopsis
946  
947 package main;
948  
949 $factory->register('data.home')->value('/home');
950  
951 $factory->register('data.root')->value('/root');
952  
953 $factory->arrayref('data.home', 'data.root');
954  
955 my $args = $factory->args;
956  
957 # ['/home', '/root']
958  
959 =back
960  
961 =over 4
962  
963 =item args example 10
964  
965 # given: synopsis
966  
967 package main;
968  
969 $factory->register('data.home')->value('/home');
970  
971 $factory->register('data.root')->value('/root');
972  
973 $factory->arrayref('data.home', 'data.root');
974  
975 my $args = $factory->args(['/boot']);
976  
977 # ['/home', '/root', '/boot']
978  
979 =back
980  
981 =over 4
982  
983 =item args example 11
984  
985 # given: synopsis
986  
987 package main;
988  
989 $factory->register('data.home')->value('/home');
990  
991 $factory->register('data.root')->value('/root');
992  
993 $factory->hashref({home => 'data.home', root => 'data.root'});
994  
995 my $args = $factory->args;
996  
997 # {home => '/home', root => '/root'}
998  
999 =back
1000  
1001 =over 4
1002  
1003 =item args example 12
1004  
1005 # given: synopsis
1006  
1007 package main;
1008  
1009 $factory->register('data.home')->value('/home');
1010  
1011 $factory->register('data.root')->value('/root');
1012  
1013 $factory->hashref({home => 'data.home', root => 'data.root'});
1014  
1015 my $args = $factory->args({boot => '/boot'});
1016  
1017 # {home => '/home', root => '/root', boot => '/boot'}
1018  
1019 =back
1020  
1021 =cut
1022  
1023 =head2 arrayref
1024  
1025 arrayref(arrayref $data) (arrayref)
1026  
1027 The arrayref method modifies the current configuration and registers an
1028 arrayref where each value is a string or arrayref representing arguments to be
1029 passed to L</build>, each value is resolved and the resulting arrayref merged
1030 with the L</value> upon resolution.
1031  
1032 I<Since C<4.15>>
1033  
1034 =over 4
1035  
1036 =item arrayref example 1
1037  
1038 # given: synopsis;
1039  
1040 my $arrayref = $factory->arrayref;
1041  
1042 # undef
1043  
1044 =back
1045  
1046 =over 4
1047  
1048 =item arrayref example 2
1049  
1050 # given: synopsis;
1051  
1052 my $arrayref = $factory->arrayref('path');
1053  
1054 # bless(..., "Venus::Factory")
1055  
1056 =back
1057  
1058 =over 4
1059  
1060 =item arrayref example 3
1061  
1062 # given: synopsis;
1063  
1064 $factory->arrayref('path');
1065  
1066 my $arrayref = $factory->arrayref;
1067  
1068 # ['path']
1069  
1070 =back
1071  
1072 =over 4
1073  
1074 =item arrayref example 4
1075  
1076 # given: synopsis;
1077  
1078 my $arrayref = $factory->arrayref(['path', '/var/log'], ['path', '/tmp/log']);
1079  
1080 # bless(..., "Venus::Factory")
1081  
1082 =back
1083  
1084 =cut
1085  
1086 =head2 assert
1087  
1088 assert(string $expr) (Venus::Factory)
1089  
1090 The assert method modifies the current configuration and registers a type
1091 expression to be used to validate the resulting object upon resolution.
1092  
1093 I<Since C<4.15>>
1094  
1095 =over 4
1096  
1097 =item assert example 1
1098  
1099 # given: synopsis;
1100  
1101 my $assert = $factory->assert;
1102  
1103 # undef
1104  
1105 =back
1106  
1107 =over 4
1108  
1109 =item assert example 2
1110  
1111 # given: synopsis;
1112  
1113 my $assert = $factory->assert('Example');
1114  
1115 # bless(..., "Venus::Factory")
1116  
1117 =back
1118  
1119 =over 4
1120  
1121 =item assert example 3
1122  
1123 # given: synopsis;
1124  
1125 $factory->assert('Example');
1126  
1127 my $assert = $factory->assert;
1128  
1129 # "Example"
1130  
1131 =back
1132  
1133 =cut
1134  
1135 =head2 attach
1136  
1137 attach(string $name, Venus::Factory $data) (Venus::Factory)
1138  
1139 The attach method adds an existing L<"detached"|/detach> container to the
1140 registry and returns container.
1141  
1142 I<Since C<4.15>>
1143  
1144 =over 4
1145  
1146 =item attach example 1
1147  
1148 # given: synopsis
1149  
1150 package main;
1151  
1152 my $attach = $factory->attach;
1153  
1154 # bless(..., "Venus::Factory")
1155  
1156 =back
1157  
1158 =over 4
1159  
1160 =item attach example 2
1161  
1162 # given: synopsis
1163  
1164 package main;
1165  
1166 my $attach = $factory->attach('path', Venus::Factory->new->class('Venus::Path'));
1167  
1168 # bless(..., "Venus::Factory")
1169  
1170 =back
1171  
1172 =cut
1173  
1174 =head2 builder
1175  
1176 builder(coderef $callback) (coderef)
1177  
1178 The builder method modifies the current configuration and registers a callback
1179 invoked during resolution which the resolved object is passed through. The
1180 return value of the callback will be returned by L</resolve>.
1181  
1182 I<Since C<4.15>>
1183  
1184 =over 4
1185  
1186 =item builder example 1
1187  
1188 # given: synopsis;
1189  
1190 my $builder = $factory->builder;
1191  
1192 # undef
1193  
1194 =back
1195  
1196 =over 4
1197  
1198 =item builder example 2
1199  
1200 # given: synopsis;
1201  
1202 my $builder = $factory->builder(sub{});
1203  
1204 # bless(..., "Venus::Factory")
1205  
1206 =back
1207  
1208 =over 4
1209  
1210 =item builder example 3
1211  
1212 # given: synopsis;
1213  
1214 $factory->builder(sub{});
1215  
1216 my $builder = $factory->builder;
1217  
1218 # sub{}
1219  
1220 =back
1221  
1222 =cut
1223  
1224 =head2 cache
1225  
1226 cache(hashref $cache) (hashref)
1227  
1228 The cache method gets and sets a store to be used by all derived containers
1229 where objects will be cached upon resolution.
1230  
1231 I<Since C<4.15>>
1232  
1233 =over 4
1234  
1235 =item cache example 1
1236  
1237 # given: synopsis;
1238  
1239 my $cache = $factory->cache;
1240  
1241 # undef
1242  
1243 =back
1244  
1245 =over 4
1246  
1247 =item cache example 2
1248  
1249 # given: synopsis;
1250  
1251 my $cache = $factory->cache({});
1252  
1253 # bless(..., "Venus::Factory")
1254  
1255 =back
1256  
1257 =over 4
1258  
1259 =item cache example 3
1260  
1261 # given: synopsis;
1262  
1263 $factory->cache(sub{});
1264  
1265 my $cache = $factory->cache;
1266  
1267 # sub{}
1268  
1269 =back
1270  
1271 =cut
1272  
1273 =head2 cached
1274  
1275 cached(boolean $bool) (Venus::Factory)
1276  
1277 The cached method modifies the current configuration and denotes that the
1278 object should be cached upon resolution.
1279  
1280 I<Since C<4.15>>
1281  
1282 =over 4
1283  
1284 =item cached example 1
1285  
1286 # given: synopsis;
1287  
1288 my $cached = $factory->cached;
1289  
1290 # undef
1291  
1292 =back
1293  
1294 =over 4
1295  
1296 =item cached example 2
1297  
1298 # given: synopsis;
1299  
1300 my $cached = $factory->cached(true);
1301  
1302 # bless(..., "Venus::Factory")
1303  
1304 =back
1305  
1306 =over 4
1307  
1308 =item cached example 3
1309  
1310 # given: synopsis;
1311  
1312 $factory->cached(true);
1313  
1314 my $cached = $factory->cached;
1315  
1316 # true
1317  
1318 =back
1319  
1320 =cut
1321  
1322 =head2 callback
1323  
1324 callback(any @args) (Venus::Factory)
1325  
1326 The callback method modifies the current configuration and denotes that a
1327 coderef containing the resolved object should be returned upon resolution.
1328  
1329 I<Since C<4.15>>
1330  
1331 =over 4
1332  
1333 =item callback example 1
1334  
1335 # given: synopsis;
1336  
1337 my $callback = $factory->callback;
1338  
1339 # sub{...}
1340  
1341 =back
1342  
1343 =over 4
1344  
1345 =item callback example 2
1346  
1347 # given: synopsis;
1348  
1349 $factory->class('Venus::Path');
1350  
1351 my $callback = $factory->callback('.');
1352  
1353 # sub{...}
1354  
1355 =back
1356  
1357 =cut
1358  
1359 =head2 chain
1360  
1361 chain(string | within[arrayref, string] @chain) (Venus::Factory)
1362  
1363 The chain method method modifies the current configuration and registers a
1364 string or arrayref representing subsequent method calls to be chained upon
1365 resolution.
1366  
1367 I<Since C<4.15>>
1368  
1369 =over 4
1370  
1371 =item chain example 1
1372  
1373 # given: synopsis;
1374  
1375 my $chain = $factory->chain;
1376  
1377 # undef
1378  
1379 =back
1380  
1381 =over 4
1382  
1383 =item chain example 2
1384  
1385 # given: synopsis;
1386  
1387 my $chain = $factory->chain('step_1');
1388  
1389 # bless(..., "Venus::Factory")
1390  
1391 =back
1392  
1393 =over 4
1394  
1395 =item chain example 3
1396  
1397 # given: synopsis;
1398  
1399 $factory->chain('step_1');
1400  
1401 my $chain = $factory->chain;
1402  
1403 # ["step_1"]
1404  
1405 =back
1406  
1407 =over 4
1408  
1409 =item chain example 4
1410  
1411 # given: synopsis;
1412  
1413 $factory->chain('step_1', 'step_2');
1414  
1415 my $chain = $factory->chain;
1416  
1417 # ["step_1", "step_2"]
1418  
1419 =back
1420  
1421 =over 4
1422  
1423 =item chain example 5
1424  
1425 # given: synopsis;
1426  
1427 $factory->chain('step_1', 'step_2', ['step_3', 1..4]);
1428  
1429 my $chain = $factory->chain;
1430  
1431 # ["step_1", "step_2", ["step_3", 1..4]]
1432  
1433 =back
1434  
1435 =cut
1436  
1437 =head2 class
1438  
1439 class(string $class) (Venus::Factory)
1440  
1441 The class method is shorthand for calling L</package>, L</assert>, and L</method> with the
1442 argument C<"new">.
1443  
1444 I<Since C<4.15>>
1445  
1446 =over 4
1447  
1448 =item class example 1
1449  
1450 # given: synopsis;
1451  
1452 my $class = $factory->class;
1453  
1454 # undef
1455  
1456 =back
1457  
1458 =over 4
1459  
1460 =item class example 2
1461  
1462 # given: synopsis;
1463  
1464 my $class = $factory->class('Venus::Path');
1465  
1466 # bless(..., "Venus::Factory")
1467  
1468 =back
1469  
1470 =over 4
1471  
1472 =item class example 3
1473  
1474 # given: synopsis;
1475  
1476 $factory->class('Venus::Path');
1477  
1478 my $class = $factory->class;
1479  
1480 # "Venus::Path"
1481  
1482 =back
1483  
1484 =cut
1485  
1486 =head2 clone
1487  
1488 clone() (Venus::Factory)
1489  
1490 The clone method clones the current configuration and returns a container not
1491 attached to the registry.
1492  
1493 I<Since C<4.15>>
1494  
1495 =over 4
1496  
1497 =item clone example 1
1498  
1499 # given: synopsis
1500  
1501 package main;
1502  
1503 my $clone = $factory->clone;
1504  
1505 # bless(..., "Venus::Factory")
1506  
1507 =back
1508  
1509 =over 4
1510  
1511 =item clone example 2
1512  
1513 # given: synopsis
1514  
1515 package main;
1516  
1517 $factory->class('Venus::Path')->name('path');
1518  
1519 my $clone = $factory->clone;
1520  
1521 # bless(..., "Venus::Factory")
1522  
1523 =back
1524  
1525 =over 4
1526  
1527 =item clone example 3
1528  
1529 # given: synopsis
1530  
1531 package main;
1532  
1533 $factory->class('Venus::Path')->builder(sub{$_->absolute})->name('path');
1534  
1535 my $clone = $factory->clone;
1536  
1537 # bless(..., "Venus::Factory")
1538  
1539 =back
1540  
1541 =cut
1542  
1543 =head2 constructor
1544  
1545 constructor(any @data) (defined)
1546  
1547 The constructor method modifies the current configuration and registers a
1548 callback invoked during resolution which is passed the package, if any, and the
1549 resolved dependencies (and/or arguments), if any. The return value of the
1550 callback will be considered the resolved object.
1551  
1552 I<Since C<4.15>>
1553  
1554 =over 4
1555  
1556 =item constructor example 1
1557  
1558 # given: synopsis;
1559  
1560 my $constructor = $factory->constructor;
1561  
1562 # undef
1563  
1564 =back
1565  
1566 =over 4
1567  
1568 =item constructor example 2
1569  
1570 # given: synopsis;
1571  
1572 my $constructor = $factory->constructor(sub{});
1573  
1574 # bless(..., "Venus::Factory")
1575  
1576 =back
1577  
1578 =over 4
1579  
1580 =item constructor example 3
1581  
1582 # given: synopsis;
1583  
1584 $factory->constructor(sub{});
1585  
1586 my $constructor = $factory->constructor;
1587  
1588 # sub{}
1589  
1590 =back
1591  
1592 =cut
1593  
1594 =head2 detach
1595  
1596 detach(string $name) (maybe[Venus::Factory])
1597  
1598 The detach method removes an existing container from the registry and returns
1599 container. The detached container will still have access to the registry to
1600 resolve dependencies. To detach from the registry use L</reset>.
1601  
1602 I<Since C<4.15>>
1603  
1604 =over 4
1605  
1606 =item detach example 1
1607  
1608 # given: synopsis
1609  
1610 package main;
1611  
1612 my $detach = $factory->detach('path');
1613  
1614 # undef
1615  
1616 =back
1617  
1618 =over 4
1619  
1620 =item detach example 2
1621  
1622 # given: synopsis
1623  
1624 package main;
1625  
1626 $factory->register('path')->class('Venus::Path');
1627  
1628 my $detach = $factory->detach('path');
1629  
1630 # bless(..., "Venus::Factory")
1631  
1632 =back
1633  
1634 =cut
1635  
1636 =head2 dispatch
1637  
1638 dispatch(string $name) (Venus::Factory)
1639  
1640 The dispatch method modifies the current configuration and denotes the
1641 subroutine that should be dispatched to upon resolution.
1642  
1643 I<Since C<4.15>>
1644  
1645 =over 4
1646  
1647 =item dispatch example 1
1648  
1649 # given: synopsis;
1650  
1651 my $dispatch = $factory->dispatch;
1652  
1653 # undef
1654  
1655 =back
1656  
1657 =over 4
1658  
1659 =item dispatch example 2
1660  
1661 # given: synopsis;
1662  
1663 my $dispatch = $factory->dispatch('do_something');
1664  
1665 # bless(..., "Venus::Factory")
1666  
1667 =back
1668  
1669 =over 4
1670  
1671 =item dispatch example 3
1672  
1673 # given: synopsis;
1674  
1675 $factory->dispatch('do_something');
1676  
1677 my $dispatch = $factory->dispatch;
1678  
1679 # "do_something"
1680  
1681 =back
1682  
1683 =cut
1684  
1685 =head2 extend
1686  
1687 extend(string $name) (Venus::Factory)
1688  
1689 The extend method copies the details of the configuration specified to the
1690 current configuration.
1691  
1692 I<Since C<4.15>>
1693  
1694 =over 4
1695  
1696 =item extend example 1
1697  
1698 # given: synopsis;
1699  
1700 $factory->register('path')->class('Venus::Path');
1701  
1702 my $extend = $factory->extend;
1703  
1704 # bless(..., "Venus::Factory")
1705  
1706 =back
1707  
1708 =over 4
1709  
1710 =item extend example 2
1711  
1712 # given: synopsis;
1713  
1714 $factory->register('path')->class('Venus::Path');
1715  
1716 my $extend = $factory->register('temp')->extend('path');
1717  
1718 # bless(..., "Venus::Factory")
1719  
1720 =back
1721  
1722 =cut
1723  
1724 =head2 function
1725  
1726 function(string $name) (Venus::Factory)
1727  
1728 The function method modifies the current configuration and denotes that object
1729 resolution should result from a function call using the function name provided.
1730  
1731 I<Since C<4.15>>
1732  
1733 =over 4
1734  
1735 =item function example 1
1736  
1737 # given: synopsis;
1738  
1739 my $function = $factory->function;
1740  
1741 # undef
1742  
1743 =back
1744  
1745 =over 4
1746  
1747 =item function example 2
1748  
1749 # given: synopsis;
1750  
1751 my $function = $factory->function('do_something');
1752  
1753 # bless(..., "Venus::Factory")
1754  
1755 =back
1756  
1757 =over 4
1758  
1759 =item function example 3
1760  
1761 # given: synopsis;
1762  
1763 $factory->function('do_something');
1764  
1765 my $function = $factory->function;
1766  
1767 # "do_something"
1768  
1769 =back
1770  
1771 =cut
1772  
1773 =head2 hashref
1774  
1775 hashref(hashref $data) (hashref)
1776  
1777 The hashref method modifies the current configuration and registers an hashref
1778 where each value is a string or arrayref representing arguments to be passed to
1779 L</build>, each value is resolved and the resulting hashref is merged with the
1780 L</value> upon resolution.
1781  
1782 I<Since C<4.15>>
1783  
1784 =over 4
1785  
1786 =item hashref example 1
1787  
1788 # given: synopsis;
1789  
1790 my $hashref = $factory->hashref;
1791  
1792 # undef
1793  
1794 =back
1795  
1796 =over 4
1797  
1798 =item hashref example 2
1799  
1800 # given: synopsis;
1801  
1802 my $hashref = $factory->hashref({path => 'path'});
1803  
1804 # bless(..., "Venus::Factory")
1805  
1806 =back
1807  
1808 =over 4
1809  
1810 =item hashref example 3
1811  
1812 # given: synopsis;
1813  
1814 $factory->hashref({path => 'path'});
1815  
1816 my $hashref = $factory->hashref;
1817  
1818 # {path => "path"}
1819  
1820 =back
1821  
1822 =over 4
1823  
1824 =item hashref example 4
1825  
1826 # given: synopsis;
1827  
1828 $factory->hashref({
1829 tmplog => ['path', '/tmp/log'],
1830 varlog => ['path', '/var/log'],
1831 });
1832  
1833 my $hashref = $factory->hashref;
1834  
1835 # {tmplog => ["path", "/tmp/log"], varlog => ["path", "/var/log"]}
1836  
1837 =back
1838  
1839 =cut
1840  
1841 =head2 list
1842  
1843 list(string | arrayref @data) (string | arrayref)
1844  
1845 The list method modifies the current configuration and registers a sequence of
1846 values where each value is a string or arrayref representing arguments to be
1847 passed to L</build>, each value is resolved and the resulting list is merged
1848 with the L</value> upon resolution.
1849  
1850 I<Since C<4.15>>
1851  
1852 =over 4
1853  
1854 =item list example 1
1855  
1856 # given: synopsis;
1857  
1858 my $list = $factory->list;
1859  
1860 # undef
1861  
1862 =back
1863  
1864 =over 4
1865  
1866 =item list example 2
1867  
1868 # given: synopsis;
1869  
1870 my $list = $factory->list('path');
1871  
1872 # bless(..., "Venus::Factory")
1873  
1874 =back
1875  
1876 =over 4
1877  
1878 =item list example 3
1879  
1880 # given: synopsis;
1881  
1882 $factory->list('path');
1883  
1884 my @list = $factory->list;
1885  
1886 # ("path")
1887  
1888 =back
1889  
1890 =over 4
1891  
1892 =item list example 4
1893  
1894 # given: synopsis;
1895  
1896 $factory->list(['path', '/var/log'], ['path', '/tmp/log']);
1897  
1898 my @list = $factory->list;
1899  
1900 # (['path', '/var/log'], ['path', '/tmp/log'])
1901  
1902 =back
1903  
1904 =cut
1905  
1906 =head2 method
1907  
1908 method(string $name) (Venus::Factory)
1909  
1910 The method method modifies the current configuration and denotes that object
1911 resolution should result from a method call using the method name provided.
1912  
1913 I<Since C<4.15>>
1914  
1915 =over 4
1916  
1917 =item method example 1
1918  
1919 # given: synopsis;
1920  
1921 my $method = $factory->method;
1922  
1923 # undef
1924  
1925 =back
1926  
1927 =over 4
1928  
1929 =item method example 2
1930  
1931 # given: synopsis;
1932  
1933 my $method = $factory->method('do_something');
1934  
1935 # bless(..., "Venus::Factory")
1936  
1937 =back
1938  
1939 =over 4
1940  
1941 =item method example 3
1942  
1943 # given: synopsis;
1944  
1945 $factory->method('do_something');
1946  
1947 my $method = $factory->method;
1948  
1949 # "do_something"
1950  
1951 =back
1952  
1953 =cut
1954  
1955 =head2 new
1956  
1957 new(hashref $data) (Venus::Factory)
1958  
1959 The new method returns a L<Venus::Factory> object.
1960  
1961 I<Since C<4.15>>
1962  
1963 =over 4
1964  
1965 =item new example 1
1966  
1967 package main;
1968  
1969 use Venus::Factory;
1970  
1971 my $factory = Venus::Factory->new;
1972  
1973 # bless(..., "Venus::Factory")
1974  
1975 =back
1976  
1977 =cut
1978  
1979 =head2 package
1980  
1981 package(string $name) (Venus::Factory)
1982  
1983 The package method modifies the current configuration and denotes that object
1984 resolution should be derived from the package name provided.
1985  
1986 I<Since C<4.15>>
1987  
1988 =over 4
1989  
1990 =item package example 1
1991  
1992 # given: synopsis;
1993  
1994 my $package = $factory->package;
1995  
1996 # undef
1997  
1998 =back
1999  
2000 =over 4
2001  
2002 =item package example 2
2003  
2004 # given: synopsis;
2005  
2006 my $package = $factory->package('Example');
2007  
2008 # bless(..., "Venus::Factory")
2009  
2010 =back
2011  
2012 =over 4
2013  
2014 =item package example 3
2015  
2016 # given: synopsis;
2017  
2018 $factory->package('Example');
2019  
2020 my $package = $factory->package;
2021  
2022 # "Example"
2023  
2024 =back
2025  
2026 =cut
2027  
2028 =head2 protocol
2029  
2030 protocol(string $name) (Venus::Factory)
2031  
2032 The protocol method modifies the current configuration and denotes the
2033 subroutine dispatch protocol that should be used upon resolution.
2034  
2035 I<Since C<4.15>>
2036  
2037 =over 4
2038  
2039 =item protocol example 1
2040  
2041 # given: synopsis;
2042  
2043 my $protocol = $factory->protocol;
2044  
2045 # undef
2046  
2047 =back
2048  
2049 =over 4
2050  
2051 =item protocol example 2
2052  
2053 # given: synopsis;
2054  
2055 my $protocol = $factory->protocol('method');
2056  
2057 # bless(..., "Venus::Factory")
2058  
2059 =back
2060  
2061 =over 4
2062  
2063 =item protocol example 3
2064  
2065 # given: synopsis;
2066  
2067 $factory->protocol('method');
2068  
2069 my $protocol = $factory->protocol;
2070  
2071 # "method"
2072  
2073 =back
2074  
2075 =cut
2076  
2077 =head2 register
2078  
2079 register(string $name) (Venus::Factory)
2080  
2081 The register method registers and returns a new container (dependency
2082 resolver).
2083  
2084 I<Since C<4.15>>
2085  
2086 =over 4
2087  
2088 =item register example 1
2089  
2090 # given: synopsis;
2091  
2092 my $register = $factory->register('path');
2093  
2094 # bless(..., "Venus::Factory")
2095  
2096 =back
2097  
2098 =cut
2099  
2100 =head2 registry
2101  
2102 registry(hashref $store) (hashref)
2103  
2104 The registry method returns a hashref representing all registered containers.
2105  
2106 I<Since C<4.15>>
2107  
2108 =over 4
2109  
2110 =item registry example 1
2111  
2112 # given: synopsis;
2113  
2114 my $registry = $factory->registry;
2115  
2116 # undef
2117  
2118 =back
2119  
2120 =over 4
2121  
2122 =item registry example 2
2123  
2124 # given: synopsis;
2125  
2126 my $registry = $factory->registry({});
2127  
2128 # bless(..., "Venus::Factory")
2129  
2130 =back
2131  
2132 =over 4
2133  
2134 =item registry example 3
2135  
2136 # given: synopsis;
2137  
2138 $factory->registry({});
2139  
2140 my $registry = $factory->registry;
2141  
2142 # {}
2143  
2144 =back
2145  
2146 =cut
2147  
2148 =head2 reset
2149  
2150 reset(string $name) (any)
2151  
2152 The reset method resets a property of the current configuration based on the
2153 name provided. If no name is provided this method will reset all properties. If
2154 a property name is provided this method returned the value of the reset
2155 property. If no property name is provided this method returns the invocant.
2156  
2157 I<Since C<4.15>>
2158  
2159 =over 4
2160  
2161 =item reset example 1
2162  
2163 # given: synopsis
2164  
2165 package main;
2166  
2167 my $reset = $factory->reset;
2168  
2169 # bless(..., "Venus::Factory")
2170  
2171 =back
2172  
2173 =over 4
2174  
2175 =item reset example 2
2176  
2177 # given: synopsis
2178  
2179 package main;
2180  
2181 $factory->class('Venus::Path')->name('path');
2182  
2183 my $reset = $factory->reset;
2184  
2185 # bless(..., "Venus::Factory")
2186  
2187 =back
2188  
2189 =over 4
2190  
2191 =item reset example 3
2192  
2193 # given: synopsis
2194  
2195 package main;
2196  
2197 $factory->class('Venus::Path')->name('path');
2198  
2199 my $reset = $factory->reset('assert');
2200  
2201 # "Venus::Path"
2202  
2203 =back
2204  
2205 =over 4
2206  
2207 =item reset example 4
2208  
2209 # given: synopsis
2210  
2211 package main;
2212  
2213 $factory->name('path');
2214  
2215 $factory->class('Venus::Path');
2216  
2217 # my $reset = $factory->reset('package');
2218  
2219 # "Venus::Path"
2220  
2221 =back
2222  
2223 =cut
2224  
2225 =head2 resolve
2226  
2227 resolve(any @args) (any)
2228  
2229 The resolve method resolves the current configuration and returns the
2230 constructed object based on the configuration. Any arguments provided (or
2231 registered L<"values"|/value>) are merged with any registered L</arrayref>,
2232 L</hashref>, or L</list> values.
2233  
2234 I<Since C<4.15>>
2235  
2236 =over 4
2237  
2238 =item resolve example 1
2239  
2240 # given: synopsis;
2241  
2242 $factory->class('Venus::Path');
2243  
2244 my $resolve = $factory->resolve;
2245  
2246 # bless(..., "Venus::Path")
2247  
2248 =back
2249  
2250 =over 4
2251  
2252 =item resolve example 2
2253  
2254 # given: synopsis;
2255  
2256 $factory->class('Venus::Path');
2257  
2258 my $resolve = $factory->resolve('.');
2259  
2260 # bless(..., "Venus::Path")
2261  
2262 =back
2263  
2264 =over 4
2265  
2266 =item resolve example 3
2267  
2268 # given: synopsis;
2269  
2270 my $resolve = $factory->register('path')->class('Venus::Path')->resolve('.');
2271  
2272 # bless(..., "Venus::Path")
2273  
2274 =back
2275  
2276 =over 4
2277  
2278 =item resolve example 4
2279  
2280 # given: synopsis;
2281  
2282 $factory->class('Venus::Log');
2283  
2284 my $resolve = $factory->resolve;
2285  
2286 # bless(..., "Venus::Log")
2287  
2288 =back
2289  
2290 =over 4
2291  
2292 =item resolve example 5
2293  
2294 # given: synopsis;
2295  
2296 $factory->register('log')->class('Venus::Log');
2297  
2298 my $resolve = $factory->resolve;
2299  
2300 # undef
2301  
2302 =back
2303  
2304 =over 4
2305  
2306 =item resolve example 6
2307  
2308 # given: synopsis;
2309  
2310 my $resolve = $factory->register('date')->class('Venus::Date')->value(570672000)->resolve;
2311  
2312 # bless(..., "Venus::Date")
2313  
2314 =back
2315  
2316 =over 4
2317  
2318 =item resolve example 7
2319  
2320 # given: synopsis;
2321  
2322 my $resolve = $factory->register('date')
2323 ->class('Venus::Date')->value({year => 1988, month => 2, day => 1})->resolve;
2324  
2325 # bless(..., "Venus::Date")
2326  
2327 =back
2328  
2329 =over 4
2330  
2331 =item resolve example 8
2332  
2333 # given: synopsis;
2334  
2335 my $resolve = $factory->register('date')
2336 ->class('Venus::Date')->value(year => 1988, month => 2, day => 1)->resolve;
2337  
2338 # bless(..., "Venus::Date")
2339  
2340 =back
2341  
2342 =over 4
2343  
2344 =item resolve example 9
2345  
2346 # given: synopsis;
2347  
2348 my $resolve = $factory->register('date')
2349 ->class('Venus::Date')->builder(sub{$_->mdy})->value(570672000)
2350 ->assert('string')
2351 ->resolve;
2352  
2353 # "02-01-1988"
2354  
2355 =back
2356  
2357 =over 4
2358  
2359 =item resolve example 10
2360  
2361 # given: synopsis;
2362  
2363 my $resolve = $factory->register('greeting')
2364 ->class('Venus::String')->builder(sub{$_->titlecase})
2365 ->assert('string')
2366 ->resolve('hello world');
2367  
2368 # "Hello World"
2369  
2370 =back
2371  
2372 =over 4
2373  
2374 =item resolve example 11
2375  
2376 # given: synopsis;
2377  
2378 $factory->register('string')->class('Venus::String')->assert('string');
2379  
2380 my $string = $factory->retrieve('string');
2381  
2382 $string->builder(sub{
2383 my ($factory, $object) = @_;
2384 return $object->titlecase;
2385 });
2386  
2387 my $resolve = $string->resolve('hello world');
2388  
2389 # "Hello World"
2390  
2391 =back
2392  
2393 =over 4
2394  
2395 =item resolve example 12
2396  
2397 # given: synopsis;
2398  
2399 my $resolve = $factory->register('md5')->package('Digest::MD5')->function('md5_hex')->resolve;
2400  
2401 # "d41d8cd98f00b204e9800998ecf8427e"
2402  
2403 =back
2404  
2405 =over 4
2406  
2407 =item resolve example 13
2408  
2409 # given: synopsis;
2410  
2411 my $resolve = $factory->register('md5')->package('Digest::MD5')->function('md5_hex')->resolve('hello');
2412  
2413 # "5d41402abc4b2a76b9719d911017c592"
2414  
2415 =back
2416  
2417 =over 4
2418  
2419 =item resolve example 14
2420  
2421 # given: synopsis;
2422  
2423 $factory->cache({});
2424  
2425 my $secret = $factory->register('secret')->cached(true)->package('Digest::MD5')->function('md5_hex');
2426  
2427 # $secret->resolve(rand);
2428  
2429 # "fa95053a9a204800ced194ffa3fc84bc"
2430  
2431 # $secret->resolve(rand);
2432  
2433 # "fa95053a9a204800ced194ffa3fc84bc"
2434  
2435 =back
2436  
2437 =over 4
2438  
2439 =item resolve example 15
2440  
2441 # given: synopsis;
2442  
2443 my $error = $factory->register('error')->class('Venus::Error');
2444  
2445 $error->constructor(sub{
2446 my ($factory, $package, $method, @args) = @_;
2447 return $package->$method(@args)->do('name', 'on.factory.build');
2448 });
2449  
2450 $error->resolve;
2451  
2452 # bless(..., "Venus::Error")
2453  
2454 =back
2455  
2456 =over 4
2457  
2458 =item resolve example 16
2459  
2460 # given: synopsis;
2461  
2462 my $resolve = $factory->register('data.home')->value('/root')->resolve;
2463  
2464 # "/root"
2465  
2466 =back
2467  
2468 =over 4
2469  
2470 =item resolve example 17
2471  
2472 # given: synopsis;
2473  
2474 my $resolve = $factory
2475 ->register('data.home')->value('/root')
2476 ->register('path.home')->class('Venus::Path')->list('data.home')
2477 ->resolve;
2478  
2479 # bless(..., "Venus::Path")
2480  
2481 =back
2482  
2483 =cut
2484  
2485 =head2 retrieve
2486  
2487 retrieve(string $name) (Venus::Factory)
2488  
2489 The retrieve method returns a registered container (dependency resolver) using
2490 the name provided. If no argument is provided the invocant is returned.
2491  
2492 I<Since C<4.15>>
2493  
2494 =over 4
2495  
2496 =item retrieve example 1
2497  
2498 # given: synopsis;
2499  
2500 $factory->register('path')->class('Venus::Path');
2501  
2502 my $retrieve = $factory->retrieve;
2503  
2504 # bless(..., "Venus::Factory")
2505  
2506 =back
2507  
2508 =over 4
2509  
2510 =item retrieve example 2
2511  
2512 # given: synopsis;
2513  
2514 $factory->register('path')->class('Venus::Path');
2515  
2516 my $retrieve = $factory->retrieve('path');
2517  
2518 # bless(..., "Venus::Factory")
2519  
2520 =back
2521  
2522 =cut
2523  
2524 =head2 routine
2525  
2526 routine(string $name) (Venus::Factory)
2527  
2528 The routine method modifies the current configuration and denotes that object
2529 resolution should result from a routine call (or package call) using the
2530 subroutine name provided.
2531  
2532 I<Since C<4.15>>
2533  
2534 =over 4
2535  
2536 =item routine example 1
2537  
2538 # given: synopsis;
2539  
2540 my $routine = $factory->routine;
2541  
2542 # undef
2543  
2544 =back
2545  
2546 =over 4
2547  
2548 =item routine example 2
2549  
2550 # given: synopsis;
2551  
2552 my $routine = $factory->routine('do_something');
2553  
2554 # bless(..., "Venus::Factory")
2555  
2556 =back
2557  
2558 =over 4
2559  
2560 =item routine example 3
2561  
2562 # given: synopsis;
2563  
2564 $factory->routine('do_something');
2565  
2566 my $routine = $factory->routine;
2567  
2568 # "do_something"
2569  
2570 =back
2571  
2572 =cut
2573  
2574 =head2 value
2575  
2576 value(any @data) (any)
2577  
2578 The value method method modifies the current configuration and registers
2579 value(s) to be provided to the L</method>, L</function>, or L</routine> upon
2580 resolution.
2581  
2582 I<Since C<4.15>>
2583  
2584 =over 4
2585  
2586 =item value example 1
2587  
2588 # given: synopsis;
2589  
2590 my $value = $factory->value;
2591  
2592 # undef
2593  
2594 =back
2595  
2596 =over 4
2597  
2598 =item value example 2
2599  
2600 # given: synopsis;
2601  
2602 my $value = $factory->value('hello world');
2603  
2604 # bless(..., "Venus::Factory")
2605  
2606 =back
2607  
2608 =over 4
2609  
2610 =item value example 3
2611  
2612 # given: synopsis;
2613  
2614 $factory->value('hello world');
2615  
2616 my @value = $factory->value;
2617  
2618 # ("hello world")
2619  
2620 =back
2621  
2622 =over 4
2623  
2624 =item value example 4
2625  
2626 # given: synopsis;
2627  
2628 $factory->value({value => 'hello world'});
2629  
2630 my @value = $factory->value;
2631  
2632 # ({value => 'hello world'})
2633  
2634 =back
2635  
2636 =over 4
2637  
2638 =item value example 5
2639  
2640 # given: synopsis;
2641  
2642 $factory->value(1..4);
2643  
2644 my @value = $factory->value;
2645  
2646 # (1..4)
2647  
2648 =back
2649  
2650 =cut
2651  
2652 =head1 AUTHORS
2653  
2654 Awncorp, C<awncorp@cpan.org>
2655  
2656 =cut
2657  
2658 =head1 LICENSE
2659  
2660 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
2661  
2662 This program is free software, you can redistribute it and/or modify it under
2663 the terms of the Apache license version 2.0.
2664  
2665 =cut
« blib/lib/Venus/Config.pm ↑ Summary blib/lib/Venus/Assert.pm »