Zing/Ring.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 63 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Zing::Ring;
2  
3 use 5.014;
4  
5 use strict;
6 use warnings;
7  
8 use registry 'Zing::Types';
9 use routines;
10  
11 use Data::Object::Class;
12 use Data::Object::ClassHas;
13  
14 extends 'Zing::Process';
15  
16 our $VERSION = '0.11'; # VERSION
17  
18 # ATTRIBUTES
19  
20 has 'processes' => (
21 is => 'ro',
22 isa => 'ArrayRef[Process]',
23 req => 1
24 );
25  
26 # METHODS
27  
28 method destroy() {
29 $_->destroy for @{$self->processes};
30  
31 return $self->next::method;
32 }
33  
34 method execute() {
35 $_->started(time) for @{$self->processes};
36  
37 $self->next::method;
38  
39 $_->destroy->stopped(time) for @{$self->processes};
40  
41 return $self;
42 }
43  
44 method exercise() {
45 $_->started(time) for @{$self->processes};
46  
47 $self->next::method;
48  
49 $_->destroy->stopped(time) for @{$self->processes};
50  
51 return $self;
52 }
53  
54 method perform() {
55 my $position = ($self->{position} ||= 0)++;
56  
57 my $process = $self->processes->[$position];
58  
59 $process->loop->exercise($process);
60  
61 delete $self->{position} if ($self->{position} + 1) > @{$self->processes};
62  
63 return $self;
64 }
65  
66 method shutdown() {
67 $_->shutdown for @{$self->processes};
68  
69 return $self->next::method;
70 }
71  
72 method winddown() {
73 $_->winddown for @{$self->processes};
74  
75 return $self->next::method;
76 }
77  
78 1;
79  
80 =encoding utf8
81  
82 =head1 NAME
83  
84 Zing::Ring - Process Ring
85  
86 =cut
87  
88 =head1 ABSTRACT
89  
90 Multi-Process Assembly Ring
91  
92 =cut
93  
94 =head1 SYNOPSIS
95  
96 use Zing::Ring;
97 use Zing::Process;
98  
99 my $ring = Zing::Ring->new(processes => [
100 Zing::Process->new,
101 Zing::Process->new,
102 ]);
103  
104 # $ring->execute;
105  
106 =cut
107  
108 =head1 DESCRIPTION
109  
110 This package provides a mechanism for joining two (or more) processes and
111 executes them as one in a turn-based manner.
112  
113 =cut
114  
115 =head1 INHERITS
116  
117 This package inherits behaviors from:
118  
119 L<Zing::Process>
120  
121 =cut
122  
123 =head1 LIBRARIES
124  
125 This package uses type constraints from:
126  
127 L<Zing::Types>
128  
129 =cut
130  
131 =head1 ATTRIBUTES
132  
133 This package has the following attributes:
134  
135 =cut
136  
137 =head2 processes
138  
139 processes(ArrayRef[Process])
140  
141 This attribute is read-only, accepts C<(ArrayRef[Process])> values, and is required.
142  
143 =cut
144  
145 =head1 METHODS
146  
147 This package implements the following methods:
148  
149 =cut
150  
151 =head2 destroy
152  
153 destroy() : Object
154  
155 The destroy method executes the C<destroy> method of all the processes in the
156 list.
157  
158 =over 4
159  
160 =item destroy example #1
161  
162 # given: synopsis
163  
164 [$ring, $ring->destroy]
165  
166 =back
167  
168 =cut
169  
170 =head2 perform
171  
172 perform() : Any
173  
174 The perform method executes the event-loop of the next process in the list with
175 each call.
176  
177 =over 4
178  
179 =item perform example #1
180  
181 # given: synopsis
182  
183 [$ring, $ring->perform]
184  
185 =back
186  
187 =cut
188  
189 =head2 shutdown
190  
191 shutdown() : Object
192  
193 The shutdown method executes the C<shutdown> method of all the processes in the
194 list.
195  
196 =over 4
197  
198 =item shutdown example #1
199  
200 # given: synopsis
201  
202 [$ring, $ring->shutdown]
203  
204 =back
205  
206 =cut
207  
208 =head2 winddown
209  
210 winddown() : Object
211  
212 The winddown method executes the C<winddown> method of all the processes in the
213 list.
214  
215 =over 4
216  
217 =item winddown example #1
218  
219 # given: synopsis
220  
221 [$ring, $ring->winddown]
222  
223 =back
224  
225 =cut
226  
227 =head1 AUTHOR
228  
229 Al Newkirk, C<awncorp@cpan.org>
230  
231 =head1 LICENSE
232  
233 Copyright (C) 2011-2019, Al Newkirk, et al.
234  
235 This is free software; you can redistribute it and/or modify it under the terms
236 of the The Apache License, Version 2.0, as elucidated in the L<"license
237 file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>.
238  
239 =head1 PROJECT
240  
241 L<Wiki|https://github.com/iamalnewkirk/zing/wiki>
242  
243 L<Project|https://github.com/iamalnewkirk/zing>
244  
245 L<Initiatives|https://github.com/iamalnewkirk/zing/projects>
246  
247 L<Milestones|https://github.com/iamalnewkirk/zing/milestones>
248  
249 L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md>
250  
251 L<Issues|https://github.com/iamalnewkirk/zing/issues>
252  
253 =cut