| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Ubic::Service::Common; |
|
2
|
|
|
|
|
|
|
$Ubic::Service::Common::VERSION = '1.60'; |
|
3
|
6
|
|
|
6
|
|
37238
|
use strict; |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
147
|
|
|
4
|
6
|
|
|
6
|
|
17
|
use warnings; |
|
|
6
|
|
|
|
|
8
|
|
|
|
6
|
|
|
|
|
166
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: common way to construct new service by specifying several callbacks |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
22
|
use Params::Validate qw(:all); |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
1154
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
25
|
use parent qw(Ubic::Service::Skeleton); |
|
|
6
|
|
|
|
|
6
|
|
|
|
6
|
|
|
|
|
43
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
263
|
use Carp; |
|
|
6
|
|
|
|
|
6
|
|
|
|
6
|
|
|
|
|
4605
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
|
16
|
11
|
|
|
11
|
1
|
9812
|
my $class = shift; |
|
17
|
11
|
|
|
|
|
360
|
my $params = validate(@_, { |
|
18
|
|
|
|
|
|
|
start => { type => CODEREF }, |
|
19
|
|
|
|
|
|
|
stop => { type => CODEREF }, |
|
20
|
|
|
|
|
|
|
status => { type => CODEREF }, |
|
21
|
|
|
|
|
|
|
name => { type => SCALAR, regex => qr/^[\w-]+$/, optional => 1 }, # violates Ubic::Service encapsulation... |
|
22
|
|
|
|
|
|
|
port => { type => SCALAR, regex => qr/^\d+$/, optional => 1 }, |
|
23
|
|
|
|
|
|
|
custom_commands => { type => HASHREF, default => {} }, |
|
24
|
|
|
|
|
|
|
user => { type => SCALAR, optional => 1 }, |
|
25
|
|
|
|
|
|
|
group => { type => SCALAR | ARRAYREF, optional => 1 }, |
|
26
|
|
|
|
|
|
|
timeout_options => { type => HASHREF, default => {} }, |
|
27
|
|
|
|
|
|
|
}); |
|
28
|
11
|
50
|
|
|
|
208
|
if ($params->{custom_commands}) { |
|
29
|
11
|
|
|
|
|
14
|
for (keys %{$params->{custom_commands}}) { |
|
|
11
|
|
|
|
|
38
|
|
|
30
|
6
|
50
|
|
|
|
21
|
ref($params->{custom_commands}{$_}) eq 'CODE' or croak "Callback expected at custom command $_"; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
} |
|
33
|
11
|
|
|
|
|
38
|
my $self = bless {%$params} => $class; |
|
34
|
11
|
|
|
|
|
78
|
return $self; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub port { |
|
38
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
39
|
0
|
|
|
|
|
0
|
return $self->{port}; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub status_impl { |
|
43
|
30
|
|
|
30
|
1
|
31
|
my $self = shift; |
|
44
|
30
|
|
|
|
|
67
|
return $self->{status}->(); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub start_impl { |
|
48
|
5
|
|
|
5
|
1
|
11
|
my $self = shift; |
|
49
|
5
|
|
|
|
|
15
|
return $self->{start}->(); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub stop_impl { |
|
53
|
8
|
|
|
8
|
1
|
9
|
my $self = shift; |
|
54
|
8
|
|
|
|
|
20
|
return $self->{stop}->(); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub timeout_options { |
|
58
|
8
|
|
|
8
|
1
|
6
|
my $self = shift; |
|
59
|
8
|
|
|
|
|
95
|
return $self->{timeout_options}; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub custom_commands { |
|
63
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
|
64
|
2
|
|
|
|
|
5
|
return keys %{$self->{custom_commands}}; |
|
|
2
|
|
|
|
|
18
|
|
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub user { |
|
68
|
16
|
|
|
16
|
1
|
17
|
my $self = shift; |
|
69
|
16
|
50
|
|
|
|
37
|
return $self->{user} if defined $self->{user}; |
|
70
|
16
|
|
|
|
|
52
|
return $self->SUPER::user(); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# copypasted from Ubic::Service::SimpleDaemon... maybe we need moose after all |
|
74
|
|
|
|
|
|
|
sub group { |
|
75
|
16
|
|
|
16
|
1
|
17
|
my $self = shift; |
|
76
|
16
|
|
|
|
|
12
|
my $groups = $self->{group}; |
|
77
|
16
|
50
|
|
|
|
57
|
return $self->SUPER::group() if not defined $groups; |
|
78
|
0
|
0
|
|
|
|
0
|
return @$groups if ref $groups eq 'ARRAY'; |
|
79
|
0
|
|
|
|
|
0
|
return $groups; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub do_custom_command { |
|
83
|
3
|
|
|
3
|
1
|
8
|
my ($self, $command) = @_; |
|
84
|
3
|
50
|
|
|
|
10
|
unless (exists $self->{custom_commands}{$command}) { |
|
85
|
0
|
|
|
|
|
0
|
croak "Command '$command' not implemented"; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
3
|
|
|
|
|
10
|
$self->{custom_commands}{$command}->(); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |