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

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 41 CC 3 SCAR 13.3
CC
3
Cov
0%
init_service
6.0
_current_state
6.0
_get_error
2.0
CRAP 3.8
1 package XAS::Lib::Services::Win32;
2  
3 our $VERSION = '0.01';
4  
5 use POE;
6 use Win32;
7 use Win32::Daemon;
8  
9 use XAS::Class
10 debug => 0,
11 version => $VERSION,
12 base => 'XAS::Base',
13 mixins => 'init_service _current_state
14 SERVICE_START_PENDING
15 SERVICE_STOP_PENDING SERVICE_PAUSE_PENDING
16 SERVICE_CONTINUE_PENDING SERVICE_CONTROL_SHUTDOWN
17 SERVICE_RUNNING SERVICE_STOPPED SERVICE_PAUSED'
18 ;
19  
20 # ----------------------------------------------------------------------
21 # Public Methods
22 # ----------------------------------------------------------------------
23  
24 sub init_service {
25 my $self = shift;
26  
27 my $alias = $self->alias;
28  
29 $self->log->debug("$alias: entering init_service() - win32");
30  
31 unless (Win32::Daemon::StartService()) {
32  
33 $self->throw_msg(
34 'xas.lib.service.win32.startup.startservice',
35 'noservice',
36 _get_error()
37 );
38  
39 }
40  
41 $self->log->debug("$alias: leaving init_service() - win32");
42  
43 }
44  
45 # ----------------------------------------------------------------------
46 # Public Events
47 # ----------------------------------------------------------------------
48  
49 # ----------------------------------------------------------------------
50 # Private Events
51 # ----------------------------------------------------------------------
52  
53 # ----------------------------------------------------------------------
54 # Private Methods
55 # ----------------------------------------------------------------------
56  
57 sub _get_error {
58  
59 return(Win32::FormatMessage(Win32::Daemon::GetLastError()));
60  
61 }
62  
63 sub _current_state {
64 my $self = shift;
65  
66 my ($state, $delay) = $self->validate_params(\@_, [
67 { optional => 1, default => undef },
68 { optional => 1, default => 0 },
69 ]);
70  
71 if (defined($state)) {
72  
73 Win32::Daemon::State($state, $delay);
74  
75 }
76  
77 return Win32::Daemon::State();
78  
79 }
80  
81 1;
82  
83 __END__
84  
85 =head1 NAME
86  
87 XAS::Lib::Services::Win32 - A mixin class for Win32 Services
88  
89 =head1 DESCRIPTION
90  
91 This module is a mixin that provides an interface between Services and
92 the Win32 SCM. It allows POE to manage the scheduling of sessions while
93 referencing the Win32 SCM event stream.
94  
95 =head1 SEE ALSO
96  
97 =over 4
98  
99 =item L<XAS|XAS>
100  
101 =back
102  
103 =head1 AUTHOR
104  
105 Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt>
106  
107 =head1 COPYRIGHT AND LICENSE
108  
109 Copyright (C) 2014 Kevin L. Esteb
110  
111 This library is free software; you can redistribute it and/or modify
112 it under the same terms as Perl itself, either Perl version 5.8.8 or,
113 at your option, any later version of Perl 5 you may have available.
114  
115 See L<http://dev.perl.org/licenses/> for more information.
116  
117 =cut