File Coverage

blib/lib/XAS/Lib/App/Service.pm
Criterion Covered Total %
statement 17 52 32.6
branch 1 8 12.5
condition n/a
subroutine 6 15 40.0
pod 4 4 100.0
total 28 79 35.4


line stmt bran cond sub pod time code
1             package XAS::Lib::App::Service;
2              
3             our $VERSION = '0.01';
4              
5             my $mixin;
6              
7             BEGIN {
8 1     1   533 $mixin = 'XAS::Lib::App::Service::Unix';
9 1 50       24 $mixin = 'XAS::Lib::App::Service::Win32' if ($^O eq 'MSWin32');
10             }
11              
12 1     1   5 use Try::Tiny;
  1         1  
  1         46  
13 1     1   449 use Pod::Usage;
  1         31417  
  1         123  
14 1     1   432 use XAS::Lib::Pidfile;
  1         2  
  1         26  
15 1     1   331 use XAS::Lib::Service;
  1         2  
  1         42  
16              
17             use XAS::Class
18 1         4 debug => 0,
19             version => $VERSION,
20             base => 'XAS::Lib::App',
21             mixin => $mixin,
22             constants => 'TRUE FALSE',
23             filesystem => 'File',
24             utils => 'dotid',
25             accessors => 'daemon service pid',
26 1     1   5 ;
  1         1  
27              
28             # ----------------------------------------------------------------------
29             # Public Methods
30             # ----------------------------------------------------------------------
31              
32             sub define_signals {
33 0     0 1   my $self = shift;
34              
35             }
36              
37             sub define_pidfile {
38 0     0 1   my $self = shift;
39              
40 0           my $script = $self->env->script;
41              
42 0           $self->log->debug('entering define_pidfile()');
43              
44 0           $self->{pid} = XAS::Lib::Pidfile->new(-pid => $$);
45              
46 0 0         if (my $num = $self->pid->is_running()) {
47              
48 0           $self->throw_msg(
49             dotid($self->class). '.define_pidfile.runerr',
50             'pid_run_error',
51             $script, $num
52             );
53              
54             }
55              
56 0 0         $self->pid->write() or
57             $self->throw_msg(
58             dotid($self->class) . '.define_pidfile.wrterr',
59             'pid_write_error',
60             $self->pid->file
61             );
62              
63 0           $self->log->debug('leaving define_pidfile()');
64              
65             }
66              
67             sub run {
68 0     0 1   my $self = shift;
69              
70 0           my $rc = $self->SUPER::run();
71              
72 0 0         if (my $pid = $self->{'pid'}) {
73              
74 0           $pid->remove();
75              
76             }
77              
78 0           return $rc;
79              
80             }
81              
82             # ----------------------------------------------------------------------
83             # Private Methods
84             # ----------------------------------------------------------------------
85              
86             sub init {
87 0     0 1   my $class = shift;
88              
89 0           my $self = $class->SUPER::init(@_);
90              
91 0           $self->{'service'} = XAS::Lib::Service->new();
92              
93 0           return $self;
94              
95             }
96              
97             sub _default_options {
98 0     0     my $self = shift;
99              
100 0           my $options = $self->SUPER::_default_options();
101              
102 0           $self->{'daemon'} = FALSE;
103              
104 0           $options->{'daemon'} = \$self->{'daemon'};
105              
106             $options->{'install'} = sub {
107 0     0     $self->install_service();
108 0           exit 0;
109 0           };
110              
111             $options->{'deinstall'} = sub {
112 0     0     $self->remove_service();
113 0           exit 0;
114 0           };
115              
116             $options->{'pid-file=s'} = sub {
117 0     0     my $pidfile = File($_[1]);
118 0           $self->env->pid_file($pidfile);
119 0           };
120              
121             $options->{'cfg-file=s'} = sub {
122 0     0     my $cfgfile = File($_[1]);
123 0           $self->env->cfg_file($cfgfile);
124 0           };
125              
126 0           return $options;
127              
128             }
129              
130             1;
131              
132             __END__