| 1 | package Zing::Loop; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 56 | ▶ | use 5.014; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 56 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 56 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 56 | ▶ | use registry 'Zing::Types'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 56 | ▶ | use routines; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 56 | ▶ | use Data::Object::Class; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 56 | ▶ | use Data::Object::ClassHas; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 56 | our $VERSION = '0.26'; # VERSION | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | # ATTRIBUTES | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 56 | has 'flow' => ( | |||||||||||||||||||
| 19 | is => 'rw', | ||||||||||||||||||||
| 20 | isa => 'Flow', | ||||||||||||||||||||
| 21 | req => 1, | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 56 | has 'last' => ( | |||||||||||||||||||
| 25 | is => 'rw', | ||||||||||||||||||||
| 26 | isa => 'Bool', | ||||||||||||||||||||
| 27 | def => 0, | ||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 56 | has 'stop' => ( | |||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||
| 32 | isa => 'Bool', | ||||||||||||||||||||
| 33 | def => 0, | ||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | # METHODS | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 0 | ▶ | method execute(Any @args) { | ||||||||||||||||||
|
Subroutine
execute: not called CC=5 SCAR=34.0
| |||||||||||||||||||||
| 39 | 0 | my $step = my $head = $self->flow; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 0 | ▶ | until ($self->stop) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 0 | $step->execute($self, @args); | |||||||||||||||||||
| 43 | 0 | ▶ | $step = $step->next || do { | ||||||||||||||||||
|
Condition0%0/3
$step->next || do {
last if $self->last;
$head
}
MC/DC0%0/2
$step->next || do {
last if $self->last;
$head
}
$step->next
do {
last if $self->last;
$head
}
Truth table0%0/3
A || B
A= $step->nextB= do {
last if $self->last;
$head
}
| |||||||||||||||||||||
| 44 | 0 | ▶ | last if $self->last; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | $head; | |||||||||||||||||||
| 46 | }; | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | return $self; | |||||||||||||||||||
| 50 | 56 | } | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | ▶ | method exercise(Any @args) { | ||||||||||||||||||
|
Subroutine
exercise: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 53 | 0 | my $step = my $head = $self->flow; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | ▶ | until (!$step) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | $step->execute($self, @args); | |||||||||||||||||||
| 57 | 0 | $step = $step->next; | |||||||||||||||||||
| 58 | 0 | ▶ | last if $self->stop; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | return $self; | |||||||||||||||||||
| 62 | 56 | } | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 56 | 1; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =encoding utf8 | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =head1 NAME | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | Zing::Loop - Event Loop | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head1 ABSTRACT | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | Process Event Loop | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =head1 SYNOPSIS | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | use Zing::Flow; | ||||||||||||||||||||
| 83 | use Zing::Loop; | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | my $loop = Zing::Loop->new( | ||||||||||||||||||||
| 86 | flow => Zing::Flow->new(name => 'init', code => sub {1}) | ||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 DESCRIPTION | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | This package provides represents the process event-loop, it is implemented as | ||||||||||||||||||||
| 94 | an infinite loop which executes L<Zing::Flow> objects. | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head1 LIBRARIES | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | This package uses type constraints from: | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | L<Zing::Types> | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | =head1 ATTRIBUTES | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | This package has the following attributes: | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =head2 flow | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | flow(Flow) | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | This attribute is read-only, accepts C<(Flow)> values, and is required. | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =head2 last | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | last(Bool) | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | This attribute is read-only, accepts C<(Bool)> values, and is optional. | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =head2 stop | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | stop(Bool) | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | This attribute is read-only, accepts C<(Bool)> values, and is optional. | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =head1 METHODS | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | This package implements the following methods: | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head2 execute | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | execute(Any @args) : Object | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | The execute method executes the event-loop indefinitely. | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | =over 4 | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | =item execute example #1 | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | # given: synopsis | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | $loop->execute; | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | =back | ||||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =head2 exercise | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | exercise(Any @args) : Object | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | The exercise method executes the event-loop and stops after the first cycle. | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =over 4 | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =item exercise example #1 | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | # given: synopsis | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | $loop->exercise; | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =back | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =over 4 | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =item exercise example #2 | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | package Loop; | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | our $i = 0; | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | my $flow_0 = Zing::Flow->new( | ||||||||||||||||||||
| 185 | name => 'flow_0', | ||||||||||||||||||||
| 186 | code => sub { | ||||||||||||||||||||
| 187 | my ($flow, $loop) = @_; $loop->stop(1); | ||||||||||||||||||||
| 188 | } | ||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||
| 190 | my $flow_1 = $flow_0->next(Zing::Flow->new( | ||||||||||||||||||||
| 191 | name => 'flow_1', | ||||||||||||||||||||
| 192 | code => sub { | ||||||||||||||||||||
| 193 | my ($flow, $loop) = @_; $i++; | ||||||||||||||||||||
| 194 | } | ||||||||||||||||||||
| 195 | )); | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | my $loop = Zing::Loop->new(flow => $flow_0); | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | $loop->exercise; | ||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | =back | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | =over 4 | ||||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | =item exercise example #3 | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | package Loop; | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | our $i = 0; | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | my $flow_0 = Zing::Flow->new( | ||||||||||||||||||||
| 212 | name => 'flow_0', | ||||||||||||||||||||
| 213 | code => sub { | ||||||||||||||||||||
| 214 | my ($flow, $loop) = @_; $loop->last(1); | ||||||||||||||||||||
| 215 | } | ||||||||||||||||||||
| 216 | ); | ||||||||||||||||||||
| 217 | my $flow_1 = $flow_0->next(Zing::Flow->new( | ||||||||||||||||||||
| 218 | name => 'flow_1', | ||||||||||||||||||||
| 219 | code => sub { | ||||||||||||||||||||
| 220 | my ($flow, $loop) = @_; $i++; | ||||||||||||||||||||
| 221 | } | ||||||||||||||||||||
| 222 | )); | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | my $loop = Zing::Loop->new(flow => $flow_0); | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | $loop->exercise; | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | =back | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | =cut | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | =head1 AUTHOR | ||||||||||||||||||||
| 233 | |||||||||||||||||||||
| 234 | Al Newkirk, C<awncorp@cpan.org> | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | =head1 LICENSE | ||||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | This is free software; you can redistribute it and/or modify it under the terms | ||||||||||||||||||||
| 241 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||||||||||||||||||||
| 242 | file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>. | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | =head1 PROJECT | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | L<Wiki|https://github.com/iamalnewkirk/zing/wiki> | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | L<Project|https://github.com/iamalnewkirk/zing> | ||||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | L<Initiatives|https://github.com/iamalnewkirk/zing/projects> | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | L<Milestones|https://github.com/iamalnewkirk/zing/milestones> | ||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md> | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | L<Issues|https://github.com/iamalnewkirk/zing/issues> | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | =cut | ||||||||||||||||||||