line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::Multiservice; |
2
|
|
|
|
|
|
|
# ABSTRACT: interface of multiservice representing several named services |
3
|
|
|
|
|
|
|
$Ubic::Multiservice::VERSION = '1.60'; |
4
|
25
|
|
|
25
|
|
6606
|
use strict; |
|
25
|
|
|
|
|
32
|
|
|
25
|
|
|
|
|
524
|
|
5
|
25
|
|
|
25
|
|
71
|
use warnings; |
|
25
|
|
|
|
|
23
|
|
|
25
|
|
|
|
|
941
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub simple_service($$); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub service_names($); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
25
|
|
|
25
|
|
92
|
use Carp; |
|
25
|
|
|
|
|
26
|
|
|
25
|
|
|
|
|
1138
|
|
14
|
25
|
|
|
25
|
|
85
|
use Params::Validate qw(:all); |
|
25
|
|
|
|
|
39
|
|
|
25
|
|
|
|
|
3188
|
|
15
|
25
|
|
|
25
|
|
106
|
use Try::Tiny; |
|
25
|
|
|
|
|
25
|
|
|
25
|
|
|
|
|
995
|
|
16
|
25
|
|
|
25
|
|
72
|
use parent qw(Ubic::Service); |
|
25
|
|
|
|
|
27
|
|
|
25
|
|
|
|
|
134
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub service($$) { |
19
|
55
|
|
|
55
|
1
|
65
|
my $self = shift; |
20
|
55
|
|
|
|
|
560
|
my ($name) = validate_pos(@_, { type => SCALAR, regex => qr{^[\w-]+(?:\.[\w-]+)*$} }); |
21
|
55
|
|
|
|
|
540
|
my @parts = split '\\.', $name; |
22
|
|
|
|
|
|
|
|
23
|
55
|
100
|
|
|
|
194
|
if ($self->{service_cache}{$name}) { |
24
|
10
|
50
|
|
|
|
20
|
if (my $error = $self->{service_cache}{$name}{error}) { |
25
|
0
|
|
|
|
|
0
|
die $error; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
else { |
28
|
10
|
|
|
|
|
28
|
return $self->{service_cache}{$name}{service}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
45
|
|
|
|
|
34
|
my $service; |
33
|
|
|
|
|
|
|
try { |
34
|
45
|
100
|
|
45
|
|
1018
|
if (@parts == 1) { |
35
|
38
|
|
|
|
|
145
|
$service = $self->simple_service($name); |
36
|
36
|
100
|
|
|
|
75
|
unless (defined $service->name) { |
37
|
5
|
|
|
|
|
7
|
$service->name($name); |
38
|
|
|
|
|
|
|
} |
39
|
36
|
|
|
|
|
117
|
$service->parent_name($self->full_name); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
|
|
|
|
|
|
# complex service |
43
|
7
|
|
|
|
|
18
|
my $top_level = $self->simple_service($parts[0]); |
44
|
7
|
50
|
|
|
|
30
|
unless ($top_level->isa('Ubic::Multiservice')) { |
45
|
0
|
|
|
|
|
0
|
croak "top-level service '$parts[0]' is not a multiservice"; |
46
|
|
|
|
|
|
|
} |
47
|
7
|
100
|
|
|
|
16
|
unless (defined $top_level->name) { |
48
|
3
|
|
|
|
|
5
|
$top_level->name($parts[0]); |
49
|
|
|
|
|
|
|
} |
50
|
7
|
|
|
|
|
16
|
$top_level->parent_name($self->full_name); |
51
|
7
|
|
|
|
|
34
|
$service = $top_level->service(join '.', @parts[1..$#parts]); |
52
|
|
|
|
|
|
|
} |
53
|
42
|
|
|
|
|
145
|
$self->{service_cache}{$name} = { service => $service }; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
catch { |
56
|
3
|
|
|
3
|
|
99
|
$self->{service_cache}{$name} = { error => $_ }; |
57
|
3
|
|
|
|
|
13
|
die $_; |
58
|
45
|
|
|
|
|
337
|
}; |
59
|
42
|
|
|
|
|
767
|
return $service; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub has_service($$) { |
64
|
23
|
|
|
23
|
1
|
1016
|
my $self = shift; |
65
|
23
|
|
|
|
|
262
|
my ($name) = validate_pos(@_, { type => SCALAR, regex => qr{^[\w-]+(?:\.[\w-]+)*$} }); |
66
|
23
|
|
|
|
|
244
|
my @parts = split '\\.', $name; |
67
|
23
|
100
|
|
|
|
57
|
if (@parts == 1) { |
68
|
17
|
|
|
|
|
60
|
return $self->has_simple_service($name); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
# complex service |
71
|
6
|
100
|
|
|
|
15
|
return undef unless $self->has_service($parts[0]); |
72
|
5
|
|
|
|
|
9
|
my $top_level = $self->service($parts[0]); |
73
|
5
|
100
|
|
|
|
18
|
unless ($top_level->isa('Ubic::Multiservice')) { |
74
|
|
|
|
|
|
|
# strange, top-level service is not a multiservice |
75
|
3
|
|
|
|
|
8
|
return undef; |
76
|
|
|
|
|
|
|
} |
77
|
2
|
|
|
|
|
7
|
return $top_level->has_service(join '.', @parts[1..$#parts]); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub services($) { |
81
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
82
|
2
|
|
|
|
|
3
|
my @services; |
83
|
2
|
|
|
|
|
59
|
for my $name ($self->service_names) { |
84
|
12
|
|
|
|
|
13
|
my $service = eval { $self->service($name) }; |
|
12
|
|
|
|
|
19
|
|
85
|
12
|
50
|
|
|
|
19
|
if ($@) { |
86
|
0
|
|
|
|
|
0
|
warn "Can't construct '$name': $@"; |
87
|
0
|
|
|
|
|
0
|
next; |
88
|
|
|
|
|
|
|
} |
89
|
12
|
|
|
|
|
17
|
push @services, $service; |
90
|
|
|
|
|
|
|
} |
91
|
2
|
|
|
|
|
14
|
return @services; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub has_simple_service($$) { |
95
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
96
|
0
|
|
|
|
|
|
my ($name) = validate_pos(@_, { type => SCALAR, regex => qr{^[\w-]+$} }); |
97
|
0
|
|
|
|
|
|
return grep { $_ eq $name } $self->service_names; |
|
0
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub multiop($) { |
101
|
0
|
|
|
0
|
1
|
|
return 'allowed'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |