blib/lib/XAS/Lib/App/Services/Unix.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 55 CC 4 SCAR 17.6
CC
4
Cov
0%
define_pidfile
12.0
define_daemon
6.0
get_service_config
2.0
CRAP 5.8
1 package XAS::Lib::App::Services::Unix;
2  
3 our $VERSION = '0.01';
4  
5 use POE;
6  
7 use XAS::Class
8 debug => 0,
9 version => $VERSION,
10 base => 'XAS::Base',
11 utils => 'daemonize dotid',
12 mixins => 'define_daemon define_pidfile get_service_config
13 install_service remove_service',
14 ;
15  
16 # ----------------------------------------------------------------------
17 # Public Methods
18 # ----------------------------------------------------------------------
19  
20 sub define_daemon {
21 my $self = shift;
22  
23 # become a daemon...
24 # interesting, "daemonize() if ($self->daemon);" doesn't work as expected
25  
26 $self->log->debug("pid = $$");
27  
28 if ($self->daemon) {
29  
30 daemonize();
31 $poe_kernel->has_forked();
32  
33 }
34  
35 $self->log->debug("pid = $$");
36  
37 }
38  
39 sub define_pidfile {
40 my $self = shift;
41  
42 my $script = $self->class->any_var('SCRIPT');
43  
44 # create a pid file, use it as a semaphore lock file
45  
46 $self->log->debug("entering define_pidfile()");
47 $self->log->debug("pid file = " . $self->env->pidfile);
48  
49 $self->{pid} = File::Pid->new({file => $self->env->pidfile->path});
50  
51 if ((my $num = $self->pid->running()) ||
52 ($self->env->pidfile->exists)) {
53  
54 if ($num) {
55  
56 $self->throw_msg(
57 dotid($self->class) . '.define_pidfile.runerr',
58 'runerr',
59 $script, $num
60 );
61  
62 } else {
63  
64 $self->throw_msg(
65 dotid($self->class) . '.define_pidfile.piderr',
66 'piderr',
67 $script
68 );
69  
70 }
71
72 }
73
74 $self->pid->write() or
75 $self->throw_msg(
76 dotid($self->class) . '.define_pidfile.wrterr',
77 'wrterr',
78 $self->pid->file
79 );
80  
81 $self->log->debug("leaving define_pidfile()");
82  
83 }
84  
85 sub get_service_config {
86 my $self = shift;
87  
88 }
89  
90 sub install_service {
91 my $self = shift;
92  
93 }
94  
95 sub remove_service {
96 my $self = shift;
97  
98 }
99  
100 # ----------------------------------------------------------------------
101 # Private Methods
102 # ----------------------------------------------------------------------
103  
104 1;
105  
106 __END__
107  
108 =head1 NAME
109  
110 XAS::Lib::Services::Unix - A mixin class for Unix Services
111  
112 =head1 SYNOPSIS
113  
114 use XAS::Lib::Services::Unix;
115  
116 =head1 DESCRIPTION
117  
118 This module provides a mixin class to define the necessary functionality for
119 a Service to run on a Unix like box.
120  
121 =head1 METHODS
122  
123 =head2 define_daemon
124  
125 This method will tell POE that the process has forked.
126  
127 =head2 get_service_config
128  
129 This method does nothing on Unix.
130  
131 =head2 install_service
132  
133 This method does nothing on Unix.
134  
135 =head2 remove_service
136  
137 This method does nothing on Unix.
138  
139 =head1 SEE ALSO
140  
141 =over 4
142  
143 =item L<XAS|XAS>
144  
145 =back
146  
147 =head1 AUTHOR
148  
149 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
150  
151 =head1 COPYRIGHT AND LICENSE
152  
153 Copyright (C) 2014 Kevin L. Esteb
154  
155 This library is free software; you can redistribute it and/or modify
156 it under the same terms as Perl itself, either Perl version 5.8.8 or,
157 at your option, any later version of Perl 5 you may have available.
158  
159 See L<http://dev.perl.org/licenses/> for more information.
160  
161 =cut