| 1 | package Zing::Logic::Kernel; | ||
| 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::Logic::Watcher'; | ||
| 15 | |||
| 16 | our $VERSION = '0.26'; # VERSION | ||
| 17 | |||
| 18 | # METHODS | ||
| 19 | |||
| 20 | method flow() { | ||
| 21 | my $step_0 = $self->next::method; | ||
| 22 | |||
| 23 | my $step_1 = Zing::Flow->new( | ||
| 24 | name => 'on_purge', | ||
| 25 | code => fun($step, $loop) { $self->trace('handle_purge_event') } | ||
| 26 | ); | ||
| 27 | |||
| 28 | $step_0->append($step_1); | ||
| 29 | $step_0 | ||
| 30 | } | ||
| 31 | |||
| 32 | method handle_purge_event() { | ||
| 33 | my $process = $self->process; | ||
| 34 | |||
| 35 | return $self if !$process->env->debug; | ||
| 36 | return $self if !$process->can('journal'); | ||
| 37 | |||
| 38 | # check every minute (60 secs) not every tick | ||
| 39 | if ($self->{purge_at}) { | ||
| 40 | return $self if $self->{purge_at} > time; | ||
| 41 | } | ||
| 42 | else { | ||
| 43 | $self->{purge_at} = time+60; | ||
| 44 | return $self; | ||
| 45 | } | ||
| 46 | |||
| 47 | $process->journal->drop if $process->journal->size > 10_000; | ||
| 48 | |||
| 49 | $self->{purge_at} = time+60; | ||
| 50 | |||
| 51 | return $self; | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; | ||
| 55 | |||
| 56 | =encoding utf8 | ||
| 57 | |||
| 58 | =head1 NAME | ||
| 59 | |||
| 60 | Zing::Logic::Kernel - Kernel Logic | ||
| 61 | |||
| 62 | =cut | ||
| 63 | |||
| 64 | =head1 ABSTRACT | ||
| 65 | |||
| 66 | Kernel Process Logic Chain | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | =head1 SYNOPSIS | ||
| 71 | |||
| 72 | use Zing::Kernel; | ||
| 73 | use Zing::Logic::Kernel; | ||
| 74 | |||
| 75 | my $logic = Zing::Logic::Kernel->new( | ||
| 76 | process => Zing::Kernel->new( | ||
| 77 | scheme => ['MyApp', [], 1] | ||
| 78 | ) | ||
| 79 | ); | ||
| 80 | |||
| 81 | # $logic->execute; | ||
| 82 | |||
| 83 | =cut | ||
| 84 | |||
| 85 | =head1 DESCRIPTION | ||
| 86 | |||
| 87 | This package provides the logic (or logic chain) to be executed by the kernel | ||
| 88 | process event-loop. | ||
| 89 | |||
| 90 | =cut | ||
| 91 | |||
| 92 | =head1 INHERITS | ||
| 93 | |||
| 94 | This package inherits behaviors from: | ||
| 95 | |||
| 96 | L<Zing::Logic::Watcher> | ||
| 97 | |||
| 98 | =cut | ||
| 99 | |||
| 100 | =head1 LIBRARIES | ||
| 101 | |||
| 102 | This package uses type constraints from: | ||
| 103 | |||
| 104 | L<Zing::Types> | ||
| 105 | |||
| 106 | =cut | ||
| 107 | |||
| 108 | =head1 ATTRIBUTES | ||
| 109 | |||
| 110 | This package has the following attributes: | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | =head2 interupt | ||
| 115 | |||
| 116 | interupt(Interupt) | ||
| 117 | |||
| 118 | This attribute is read-only, accepts C<(Interupt)> values, and is optional. | ||
| 119 | |||
| 120 | =cut | ||
| 121 | |||
| 122 | =head2 on_perform | ||
| 123 | |||
| 124 | on_perform(CodeRef) | ||
| 125 | |||
| 126 | This attribute is read-only, accepts C<(CodeRef)> values, and is optional. | ||
| 127 | |||
| 128 | =cut | ||
| 129 | |||
| 130 | =head2 on_receive | ||
| 131 | |||
| 132 | on_receive(CodeRef) | ||
| 133 | |||
| 134 | This attribute is read-only, accepts C<(CodeRef)> values, and is optional. | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | =head2 on_register | ||
| 139 | |||
| 140 | on_register(CodeRef) | ||
| 141 | |||
| 142 | This attribute is read-only, accepts C<(CodeRef)> values, and is optional. | ||
| 143 | |||
| 144 | =cut | ||
| 145 | |||
| 146 | =head2 on_reset | ||
| 147 | |||
| 148 | on_reset(CodeRef) | ||
| 149 | |||
| 150 | This attribute is read-only, accepts C<(CodeRef)> values, and is optional. | ||
| 151 | |||
| 152 | =cut | ||
| 153 | |||
| 154 | =head2 on_suicide | ||
| 155 | |||
| 156 | on_suicide(CodeRef) | ||
| 157 | |||
| 158 | This attribute is read-only, accepts C<(CodeRef)> values, and is optional. | ||
| 159 | |||
| 160 | =cut | ||
| 161 | |||
| 162 | =head2 process | ||
| 163 | |||
| 164 | process(Process) | ||
| 165 | |||
| 166 | This attribute is read-only, accepts C<(Process)> values, and is required. | ||
| 167 | |||
| 168 | =cut | ||
| 169 | |||
| 170 | =head1 METHODS | ||
| 171 | |||
| 172 | This package implements the following methods: | ||
| 173 | |||
| 174 | =cut | ||
| 175 | |||
| 176 | =head2 flow | ||
| 177 | |||
| 178 | flow() : Flow | ||
| 179 | |||
| 180 | The flow method builds and returns the logic flow for the process event-loop. | ||
| 181 | |||
| 182 | =over 4 | ||
| 183 | |||
| 184 | =item flow example #1 | ||
| 185 | |||
| 186 | # given: synopsis | ||
| 187 | |||
| 188 | my $flow = $logic->flow; | ||
| 189 | |||
| 190 | =back | ||
| 191 | |||
| 192 | =cut | ||
| 193 | |||
| 194 | =head2 signals | ||
| 195 | |||
| 196 | signals() : HashRef | ||
| 197 | |||
| 198 | The signals method builds and returns the process signal handlers. | ||
| 199 | |||
| 200 | =over 4 | ||
| 201 | |||
| 202 | =item signals example #1 | ||
| 203 | |||
| 204 | # given: synopsis | ||
| 205 | |||
| 206 | my $signals = $logic->signals; | ||
| 207 | |||
| 208 | =back | ||
| 209 | |||
| 210 | =cut | ||
| 211 | |||
| 212 | =head1 AUTHOR | ||
| 213 | |||
| 214 | Al Newkirk, C<awncorp@cpan.org> | ||
| 215 | |||
| 216 | =head1 LICENSE | ||
| 217 | |||
| 218 | Copyright (C) 2011-2019, Al Newkirk, et al. | ||
| 219 | |||
| 220 | This is free software; you can redistribute it and/or modify it under the terms | ||
| 221 | of the The Apache License, Version 2.0, as elucidated in the L<"license | ||
| 222 | file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>. | ||
| 223 | |||
| 224 | =head1 PROJECT | ||
| 225 | |||
| 226 | L<Wiki|https://github.com/iamalnewkirk/zing/wiki> | ||
| 227 | |||
| 228 | L<Project|https://github.com/iamalnewkirk/zing> | ||
| 229 | |||
| 230 | L<Initiatives|https://github.com/iamalnewkirk/zing/projects> | ||
| 231 | |||
| 232 | L<Milestones|https://github.com/iamalnewkirk/zing/milestones> | ||
| 233 | |||
| 234 | L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md> | ||
| 235 | |||
| 236 | L<Issues|https://github.com/iamalnewkirk/zing/issues> | ||
| 237 | |||
| 238 | =cut |