Zing/Daemon.pm

filter: Statementstmt 35.7% 55 / 154 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 11 / 22 Podpod 25.0% 2 / 8 totaltotal 29.8% 68 / 228 CC 23 SCAR 34.8
CC
23
Cov
28%
__ANON__
110.0
fork
30.0
start
20.0
CRAP 32.5
« Zing/Term.pm ↑ Summary Zing/Logic/Timer.pm »
1 package Zing::Daemon;
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 extends 'Zing::Entity';
15  
16 56 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 56 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 56 ▶use FlightRecorder;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 56 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 56 our $VERSION = '0.26'; # VERSION
22  
23 # ATTRIBUTES
24  
25 56 has cartridge => (
26 is => 'ro',
27 isa => 'Cartridge',
28 req => 1,
29 );
30  
31 56 has logger => (
32 is => 'ro',
33 isa => 'Logger',
34 new => 1,
35 );
36  
37 0 ▶fun new_logger($self) {
Subroutine new_logger: not called CC=1 SCAR=6.9
Pod undocumented
38 0 $self->app->logger
39 56 }
40  
41 56 has journal => (
42 is => 'ro',
43 isa => 'Journal',
44 new => 1,
45 );
46  
47 0 ▶fun new_journal($self) {
Subroutine new_journal: not called CC=1 SCAR=6.9
Pod undocumented
48 0 $self->app->journal(
49 level => $self->log_level,
50 verbose => $self->log_verbose,
51 )
52 56 }
53  
54 56 has kernel => (
55 is => 'ro',
56 isa => 'Zing',
57 new => 1,
58 );
59  
60 0 ▶fun new_kernel($self) {
Subroutine new_kernel: not called CC=1 SCAR=6.9
Pod undocumented
61 0 $self->app->zing(scheme => $self->cartridge->scheme)
62 56 }
63  
64 56 has log_filter_from => (
65 is => 'ro',
66 isa => 'Str',
67 opt => 1,
68 );
69  
70 56 has log_filter_queries => (
71 is => 'ro',
72 isa => 'ArrayRef[Str]',
73 opt => 1,
74 );
75  
76 56 has log_filter_tag => (
77 is => 'ro',
78 isa => 'Str',
79 opt => 1,
80 );
81  
82 56 has log_level => (
83 is => 'ro',
84 isa => 'Str',
85 def => 'debug',
86 );
87  
88 56 has log_reset => (
89 is => 'ro',
90 isa => 'Bool',
91 def => 0,
92 );
93  
94 56 has log_verbose => (
95 is => 'ro',
96 isa => 'Bool',
97 def => 0,
98 );
99  
100 # METHODS
101  
102 0 ▶method fork() {
Subroutine fork: not called CC=5 SCAR=34.0
103 0 ▶ if ($Config{d_pseudofork}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Zing::Daemon::Config{"d_pseudofork"}) 0 0 0
104 0 $self->throw(error_fork("emulation not supported"));
105 }
106  
107 0 my $pid = fork;
108  
109 0 ▶ if (!defined $pid) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $pid) { } 0 0 0
elsif ($pid == 0) { } 0 0 0
110 0 $self->throw(error_fork("$!"));
111 }
112 elsif ($pid == 0) {
113 0 ▶ $self->throw(error_fork("terminal detach failed")) if POSIX::setsid() < 0;
Branch: 1 branch
BranchTrueFalseTotal
if POSIX::setsid() < 0 0 0 0
114 0 $self->kernel->start; # child
115 0 unlink $self->cartridge->pidfile;
116 0 POSIX::_exit(0);
117 }
118  
119 0 return $pid;
120 56 }
121  
122 0 ▶method logs(CodeRef $callback) {
Subroutine logs: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
Ref::Util::XS::is_plain_coderef($callback) or Function::Parameters::_croak('In method logs: parameter 1 ($callback): ' . ${my $v = bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_CodeRef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_ eq 'CODE';},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 452,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "CodeRef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; !$Type::Tiny::AvoidCallbacks ? "Ref::Util::XS::is_plain_coderef($_[1])" : "ref($_[1]) eq 'CODE'";},"library" => "Types::Standard","name" => "CodeRef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; not ref $_[0] and _failed_check(16, 'Ref', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Ref","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref $_;},"constraint_generator" => sub { package Types::Standard; no warnings; use strict; return $meta->get_type('Ref') unless @_; Type::Tiny::check_parameter_count_for_parameterized_type('Types::Standard', 'Ref', \@_, 1); my $reftype = shift(); $reftype =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|REGEXP|Regexp)$/i or _croak "Parameter to Ref[`a] expected to be a Perl ref type; got $reftype"; $reftype = "$reftype"; return sub { ref $_[0] and builtin::reftype($_[0]) eq $reftype; } ;},"deep_explanation" => sub { package Types::Standard; no warnings; use strict; require B; my($type, $value, $varname) = @_; my $param = $type->parameters->[0]; return if $type->check($value); my $reftype = builtin::reftype($value); return [sprintf('"%s" constrains reftype(%s) to be equal to %s', $type, $varname, B::perlstring($param)), sprintf('reftype(%s) is %s', $varname, defined $reftype ? B::perlstring($reftype) : 'undef')];},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 438,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Ref","exception_class" => "Error::TypeTiny::Assertion","inline_generator" => sub { package Types::Standard; no warnings; use strict; my $reftype = shift(); return sub { my $v = $_[1]; &$maybe_load_modules('Scalar::Util', "ref($v) and Scalar::Util::reftype($v) eq q($reftype)"); } ;},"inlined" => sub { package Types::Standard; no warnings; use strict; "!!ref($_[1])";},"library" => "Types::Standard","name" => "Ref","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 16}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return sub { } ;},"uniq" => 17}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"};$v->{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"};$v->{"parent"}{"parent"}{"parent"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}; \$v}->get_message($callback)) 0 0 0
123 0 my $journal = $self->journal;
124  
125 0 ▶ if ($self->log_reset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log_reset) 0 0 0
126 0 $journal->reset;
127 }
128  
129 0 ▶ $journal->stream(fun ($info, $data, $lines) {
Subroutine __ANON__: not called CC=10 SCAR=47.0
130 0 my $cont = 1;
131  
132 0 my $from = $info->{from};
133 0 ▶ my $tag = $info->{data}{tag} || '--';
Condition0%0/2
$info->{'data'}{'tag'} || '--'
l!l
00
MC/DC0%0/1
$info->{'data'}{'tag'} || '--'
$info->{'data'}{'tag'}
Truth table0%0/2
A
A= $info->{'data'}{'tag'}
Aresult
11
00
134  
135 0 ▶ if (my $filter = $self->log_filter_from) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $filter = $self->log_filter_from) 0 0 0
136 0 ▶ $cont = 0 unless $from =~ /$filter/;
Branch: 1 branch
BranchTrueFalseTotal
unless $from =~ /$filter/u 0 0 0
137 }
138  
139 0 ▶ if (my $filter = $self->log_filter_tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $filter = $self->log_filter_tag) 0 0 0
140 0 ▶ $cont = 0 unless $tag =~ /$filter/;
Branch: 1 branch
BranchTrueFalseTotal
unless $tag =~ /$filter/u 0 0 0
141 }
142  
143 0 ▶ if (my $queries = $self->log_filter_queries) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $queries = $self->log_filter_queries) 0 0 0
144 0 for my $query (@$queries) {
145 0 @$lines = grep /$query/, @$lines;
146 }
147 }
148  
149 0 ▶ if ($cont) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cont) 0 0 0
150 0 for my $line (@$lines) {
151 0 $callback->(join ' ', $from, ' ', $tag, ' ', $line);
152 }
153 }
154 0 });
155  
156 0 return 1;
157 56 }
158  
159 0 ▶method restart() {
Subroutine restart: not called CC=2 SCAR=17.9
Pod documented
160 0 ▶ return $self->stop && $self->start;
Condition0%0/3
$self->stop && $self->start
!ll&&!rl&&r
000
MC/DC0%0/2
$self->stop && $self->start
$self->stop $self->start
Truth table0%0/3
A && B
A= $self->stopB= $self->start
ABresult
0X0
100
111
161 56 }
162  
163 0 ▶method start() {
Subroutine start: not called CC=4 SCAR=30.0
164 0 my $logger = $self->logger;
165 0 my $cartridge = $self->cartridge;
166 0 my $file = $cartridge->pidfile;
167  
168 0 ▶ if (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) 0 0 0
169 0 $logger->fatal("pid file exists: $file");
170 0 return 0;
171 }
172  
173 0 ▶ open(my $fh, ">", "$file") or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "$file" or do { $logger->fatal("pid file error: $!"); return 0 } 0 0 0
174 0 $logger->fatal("pid file error: $!");
175 0 return 0;
176 };
177  
178 0 my ($cnt, $err) = do {
179 0 local $@;
180 0 (eval{chmod(0644, $file)}, $@)
181 };
182 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
183 0 $logger->fatal("pid file error: $err");
184 0 return 0;
185 }
186  
187 0 my $pid = $self->fork;
188 0 my $name = $cartridge->name;
189  
190 0 print $fh "$pid\n";
191 0 close $fh;
192  
193 0 $logger->info("app created: $name");
194 0 $logger->info("pid file created: $file");
195  
196 0 return 1;
197 56 }
198  
199 0 ▶method stop() {
Subroutine stop: not called CC=2 SCAR=17.9
Pod documented
200 0 my $logger = $self->logger;
201 0 my $cartridge = $self->cartridge;
202 0 my $file = $cartridge->pidfile;
203 0 my $pid = $cartridge->pid;
204  
205 0 unlink $file;
206  
207 0 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pid) { } 0 0 0
208 0 $logger->warn("no pid in file: $file");
209 }
210 else {
211 0 kill 'TERM', $pid;
212 }
213  
214 0 return 1;
215 56 }
216  
217 0 ▶method update() {
Subroutine update: not called CC=2 SCAR=17.9
Pod undocumented
218 0 my $logger = $self->logger;
219 0 my $cartridge = $self->cartridge;
220 0 my $file = $cartridge->pidfile;
221 0 my $pid = $cartridge->pid;
222  
223 0 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pid) { } 0 0 0
224 0 $logger->fatal("no pid in file: $file");
225 0 return 0;
226 }
227 else {
228 0 kill 'USR2', $pid;
229 }
230  
231 0 return 1;
232 56 }
233  
234 # ERRORS
235  
236 0 ▶fun error_fork(Str $reason) {
Subroutine error_fork: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
Type::Tiny::XS::Str($reason) or Function::Parameters::_croak('In fun error_fork: parameter 1 ($reason): ' . ${my $v = bless( {"_is_core" => 1,"_overload_coderef" => sub { package Sub::Defer; use warnings; use strict; $undeferred ||= undefer_sub($deferred_info->[4]); goto \&$undeferred;},"_overload_coderef_no_rebuild" => 1,"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Str","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; ref \$_ eq 'SCALAR' or ref \(my $val = $_) eq 'SCALAR';},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 291,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Str","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; use warnings; use strict; $Type::Tiny::AvoidCallbacks ? goto $orig_inlined : "$xsubname($_[1])";},"library" => "Types::Standard","name" => "Str","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and not ref $_[0] or _failed_check(8, 'Value', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Value","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Types::Standard; no warnings; use strict; not ref $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 276,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Value","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1]) and not ref($_[1])";},"library" => "Types::Standard","name" => "Value","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] or _failed_check(7, 'Defined', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Defined","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; defined $_[0] and _failed_check(6, 'Undef', $_[0], 'exception_class', 'Error::TypeTiny::Assertion'); $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Undef","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complementary_type" => {},"constraint" => sub { package Types::Standard; no warnings; use strict; not defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 254,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Undef","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "!defined($_[1])";},"library" => "Types::Standard","name" => "Undef","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => sub ;,"display_name" => "to_Item","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"constraint" => sub { package Type::Tiny; use warnings; use strict; !0;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 226,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Item","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Item","parent" => bless( {"_is_core" => 1,"_overload_coderef" => sub { package Type::Tiny; BEGIN {${^WARNING_BITS} = "\x10\x01\x00\x00\x00\x50\x04\x00\x00\x00\x00\x00\x01\x40\x05\x45\x55\x15\x55\x55\x01\x00"} use strict; '???'; $_[0];},"_overrides_assert_return" => !!0,"coercion" => bless( {"_compiled_type_constraint_check" => do{my $o},"display_name" => "to_Any","frozen" => 1,"name" => "__ANON__","type_coercion_map" => [],"type_constraint" => {}}, 'Type::Coercion' ),"compiled_type_constraint" => do{my $o},"complement_name" => "None","constraint" => do{my $o},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 220,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Any","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; '!!1';},"library" => "Types::Standard","name" => "Any","type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 1}, 'Type::Tiny' ),"uniq" => 2}, 'Type::Tiny' ),"type_default" => sub { package Types::Standard; no warnings; use strict; return undef;},"uniq" => 6}, 'Type::Tiny' ),"constraint" => sub { package Types::Standard; no warnings; use strict; defined $_;},"definition_context" => {"file" => "/usr/local/lib/perl5/site_perl/5.44.0/Types/Standard.pm","line" => 262,"package" => "Types::Standard"},"deprecated" => !!0,"display_name" => "Defined","exception_class" => "Error::TypeTiny::Assertion","inlined" => sub { package Types::Standard; no warnings; use strict; "defined($_[1])";},"library" => "Types::Standard","name" => "Defined","parent" => {},"uniq" => 7}, 'Type::Tiny' ),"uniq" => 8}, 'Type::Tiny' ),"sorter" => sub { package Types::Standard; no warnings; use strict; $_[0] cmp $_[1];},"type_default" => sub { package Types::Standard; no warnings; use strict; return '';},"uniq" => 9}, 'Type::Tiny' );$v->{"coercion"}{"type_constraint"} = $v;$v->{"compiled_type_constraint"} = $v->{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"};$v->{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"};$v->{"parent"}{"parent"}{"complementary_type"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"complementary_type"} = $v->{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"coercion"}{"type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"compiled_type_constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"coercion"}{"_compiled_type_constraint_check"};$v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"parent"}{"constraint"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}{"constraint"};$v->{"parent"}{"parent"}{"parent"} = $v->{"parent"}{"parent"}{"complementary_type"}{"parent"}; \$v}->get_message($reason)) 0 0 0
237 0 code => 'error_fork',
238 message => "Error on fork: $reason",
239 56 }
240  
241 56 1;
242  
243 =encoding utf8
244  
245 =head1 NAME
246  
247 Zing::Daemon - Process Daemon
248  
249 =cut
250  
251 =head1 ABSTRACT
252  
253 Daemon Process Management
254  
255 =cut
256  
257 =head1 SYNOPSIS
258  
259 use Zing::Cartridge;
260 use Zing::Daemon;
261  
262 my $daemon = Zing::Daemon->new(
263 cartridge => Zing::Cartridge->new(
264 name => 'example',
265 scheme => ['MyApp', [], 1],
266 )
267 );
268  
269 # $daemon->start;
270  
271 =cut
272  
273 =head1 DESCRIPTION
274  
275 This package provides the mechanisms for running a L<Zing> application
276 as a daemon process.
277  
278 =cut
279  
280 =head1 INHERITS
281  
282 This package inherits behaviors from:
283  
284 L<Zing::Entity>
285  
286 =cut
287  
288 =head1 LIBRARIES
289  
290 This package uses type constraints from:
291  
292 L<Zing::Types>
293  
294 =cut
295  
296 =head1 ATTRIBUTES
297  
298 This package has the following attributes:
299  
300 =cut
301  
302 =head2 cartridge
303  
304 cartridge(Cartridge)
305  
306 This attribute is read-only, accepts C<(Cartridge)> values, and is required.
307  
308 =cut
309  
310 =head2 journal
311  
312 journal(Journal)
313  
314 This attribute is read-only, accepts C<(Journal)> values, and is optional.
315  
316 =cut
317  
318 =head2 kernel
319  
320 kernel(Zing)
321  
322 This attribute is read-only, accepts C<(Zing)> values, and is optional.
323  
324 =cut
325  
326 =head2 log_filter_from
327  
328 log_filter_from(Str)
329  
330 This attribute is read-only, accepts C<(Str)> values, and is optional.
331  
332 =cut
333  
334 =head2 log_filter_queries
335  
336 log_filter_queries(ArrayRef[Str])
337  
338 This attribute is read-only, accepts C<(ArrayRef[Str])> values, and is optional.
339  
340 =cut
341  
342 =head2 log_filter_tag
343  
344 log_filter_tag(Str)
345  
346 This attribute is read-only, accepts C<(Str)> values, and is optional.
347  
348 =cut
349  
350 =head2 log_level
351  
352 log_level(Str)
353  
354 This attribute is read-only, accepts C<(Str)> values, and is optional.
355  
356 =cut
357  
358 =head2 log_reset
359  
360 log_reset(Bool)
361  
362 This attribute is read-only, accepts C<(Bool)> values, and is optional.
363  
364 =cut
365  
366 =head2 log_verbose
367  
368 log_verbose(Bool)
369  
370 This attribute is read-only, accepts C<(Bool)> values, and is optional.
371  
372 =cut
373  
374 =head2 logger
375  
376 logger(Logger)
377  
378 This attribute is read-only, accepts C<(Logger)> values, and is optional.
379  
380 =cut
381  
382 =head1 METHODS
383  
384 This package implements the following methods:
385  
386 =cut
387  
388 =head2 fork
389  
390 fork() : Int
391  
392 The fork method forks the application and returns a pid.
393  
394 =over 4
395  
396 =item fork example #1
397  
398 # given: synopsis
399  
400 my $pid = $daemon->fork;
401  
402 =back
403  
404 =cut
405  
406 =head2 restart
407  
408 restart() : Bool
409  
410 The restart method stops and then starts the application and creates a pid file
411 under the L<Zing::Cartridge/pidfile>.
412  
413 =over 4
414  
415 =item restart example #1
416  
417 use FlightRecorder;
418 use Zing::Cartridge;
419 use Zing::Daemon;
420  
421 my $daemon = Zing::Daemon->new(
422 logger => FlightRecorder->new(auto => undef),
423 cartridge => Zing::Cartridge->new(
424 name => 'example',
425 scheme => ['MyApp', [], 1],
426 )
427 );
428  
429 $daemon->restart;
430  
431 =back
432  
433 =cut
434  
435 =head2 start
436  
437 start() : Bool
438  
439 The start method forks the application and creates a pid file under the
440 L<Zing::Cartridge/pidfile>.
441  
442 =over 4
443  
444 =item start example #1
445  
446 use FlightRecorder;
447 use Zing::Cartridge;
448 use Zing::Daemon;
449  
450 my $daemon = Zing::Daemon->new(
451 logger => FlightRecorder->new(auto => undef),
452 cartridge => Zing::Cartridge->new(
453 name => 'example',
454 scheme => ['MyApp', [], 1],
455 )
456 );
457  
458 $daemon->start;
459  
460 =back
461  
462 =cut
463  
464 =head2 stop
465  
466 stop() : Bool
467  
468 The stop method stops the application and removes the pid file under the
469 L<Zing::Cartridge/pidfile>.
470  
471 =over 4
472  
473 =item stop example #1
474  
475 use FlightRecorder;
476 use Zing::Cartridge;
477 use Zing::Daemon;
478  
479 my $daemon = Zing::Daemon->new(
480 logger => FlightRecorder->new(auto => undef),
481 cartridge => Zing::Cartridge->new(
482 name => 'example',
483 scheme => ['MyApp', [], 1],
484 )
485 );
486  
487 $daemon->stop;
488  
489 =back
490  
491 =cut
492  
493 =head1 AUTHOR
494  
495 Al Newkirk, C<awncorp@cpan.org>
496  
497 =head1 LICENSE
498  
499 Copyright (C) 2011-2019, Al Newkirk, et al.
500  
501 This is free software; you can redistribute it and/or modify it under the terms
502 of the The Apache License, Version 2.0, as elucidated in the L<"license
503 file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>.
504  
505 =head1 PROJECT
506  
507 L<Wiki|https://github.com/iamalnewkirk/zing/wiki>
508  
509 L<Project|https://github.com/iamalnewkirk/zing>
510  
511 L<Initiatives|https://github.com/iamalnewkirk/zing/projects>
512  
513 L<Milestones|https://github.com/iamalnewkirk/zing/milestones>
514  
515 L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md>
516  
517 L<Issues|https://github.com/iamalnewkirk/zing/issues>
518  
519 =cut
« Zing/Term.pm ↑ Summary Zing/Logic/Timer.pm »