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

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 49 CC 5 SCAR 23.9
CC
5
Cov
0%
session_interrupt
20.0
_current_state
6.0
init_service
2.0
CRAP 10.9
1 package XAS::Lib::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 constant => {
12 SERVICE_START_PENDING => 1,
13 SERVICE_STOP_PENDING => 2,
14 SERVICE_PAUSE_PENDING => 3,
15 SERVICE_CONTINUE_PENDING => 4,
16 SERVICE_CONTROL_SHUTDOWN => 5,
17 SERVICE_RUNNING => 6,
18 SERVICE_STOPPED => 7,
19 SERVICE_PAUSED => 8,
20 },
21 mixins => 'init_service _current_state session_interrupt
22 SERVICE_START_PENDING SERVICE_STOP_PENDING
23 SERVICE_PAUSE_PENDING SERVICE_CONTINUE_PENDING
24 SERVICE_CONTROL_SHUTDOWN SERVICE_RUNNING
25 SERVICE_STOPPED SERVICE_PAUSED',
26 ;
27  
28 # ----------------------------------------------------------------------
29 # Public Methods
30 # ----------------------------------------------------------------------
31  
32 sub init_service {
33 my $self = shift;
34  
35 my $alias = $self->alias;
36  
37 $self->log->debug("$alias: entering init_service() - unix");
38  
39 $poe_kernel->sig('CONT', 'session_interrupt');
40 $poe_kernel->sig('TSTP', 'session_interrupt');
41  
42 $self->log->debug("$alias: leaving int_service() - unix");
43  
44 }
45  
46 sub session_interrupt {
47 my $self = shift;
48 my $signal = shift;
49  
50 my $alias = $self->alias;
51  
52 $self->log->debug("$alias: session_interrupt()");
53 $self->log->warn_msg('signaled', $alias, $signal);
54  
55 if ($signal eq 'HUP') {
56  
57 $self->session_reload();
58  
59 } elsif ($signal eq 'CONT') {
60  
61 $poe_kernel->sig_handled();
62 $self->_current_state(SERVICE_CONTINUE_PENDING);
63  
64 } elsif ($signal eq 'TSTP') {
65  
66 $poe_kernel->sig_handled();
67 $self->_current_state(SERVICE_PAUSE_PENDING);
68  
69 } else { # INT, TERM, QUIT
70  
71 $poe_kernel->sig_handled();
72 $self->_current_state(SERVICE_CONTROL_SHUTDOWN);
73  
74 }
75  
76 }
77  
78 # ----------------------------------------------------------------------
79 # Public Events
80 # ----------------------------------------------------------------------
81  
82 # ----------------------------------------------------------------------
83 # Private Events
84 # ----------------------------------------------------------------------
85  
86 # ----------------------------------------------------------------------
87 # Private Methods
88 # ----------------------------------------------------------------------
89  
90 sub _current_state {
91 my $self = shift;
92 my ($state, $delay) = $self->validate_params(\@_, [
93 { optional => 1, default => undef },
94 { optional => 1, default => 0 },
95 ]);
96  
97 if (defined($state)) {
98  
99 $self->{state} = $state;
100  
101 }
102  
103 return $self->{state};
104  
105 }
106  
107 1;
108  
109 __END__
110  
111 =head1 NAME
112  
113 XAS::Lib::Services::Unix - A mixin class for Unix Services
114  
115 =head1 DESCRIPTION
116  
117 This module is a mixin that provides an interface between a Unix like system
118 and a Service. It responds to these additional signals.
119  
120 TSTP - pause the session
121 CONT - resume the session
122  
123 It allows POE to manage the scheduling of sessions while handling the
124 additional signals to emulate the Windows SCM.
125  
126 =head1 SEE ALSO
127  
128 =over 4
129  
130 =item L<XAS|XAS>
131  
132 =back
133  
134 =head1 AUTHOR
135  
136 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
137  
138 =head1 COPYRIGHT AND LICENSE
139  
140 Copyright (C) 2014 Kevin L. Esteb
141  
142 This library is free software; you can redistribute it and/or modify
143 it under the same terms as Perl itself, either Perl version 5.8.8 or,
144 at your option, any later version of Perl 5 you may have available.
145  
146 See L<http://dev.perl.org/licenses/> for more information.
147  
148 =cut