line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::Settings; |
2
|
|
|
|
|
|
|
$Ubic::Settings::VERSION = '1.60'; |
3
|
26
|
|
|
26
|
|
1673
|
use strict; |
|
26
|
|
|
|
|
23
|
|
|
26
|
|
|
|
|
512
|
|
4
|
26
|
|
|
26
|
|
60
|
use warnings; |
|
26
|
|
|
|
|
33
|
|
|
26
|
|
|
|
|
532
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: ubic settings |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
26
|
|
|
26
|
|
76
|
use Params::Validate qw(:all); |
|
26
|
|
|
|
|
21
|
|
|
26
|
|
|
|
|
3660
|
|
10
|
|
|
|
|
|
|
|
11
|
26
|
|
|
26
|
|
6323
|
use Ubic::Settings::ConfigFile; |
|
26
|
|
|
|
|
39
|
|
|
26
|
|
|
|
|
9642
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $settings; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _file_settings { |
16
|
23
|
|
|
23
|
|
38
|
my $file_settings = {}; |
17
|
23
|
|
|
|
|
33
|
my @files; |
18
|
23
|
50
|
|
|
|
106
|
if ($ENV{HOME}) { |
19
|
23
|
|
|
|
|
78
|
push @files, "$ENV{HOME}/.ubic.cfg"; |
20
|
|
|
|
|
|
|
} |
21
|
23
|
|
|
|
|
66
|
push @files, '/etc/ubic/ubic.cfg'; |
22
|
23
|
|
|
|
|
59
|
push @files, '/usr/local/etc/ubic/ubic.cfg'; |
23
|
23
|
|
|
|
|
53
|
for my $file (@files) { |
24
|
69
|
50
|
|
|
|
884
|
next unless -e $file; |
25
|
0
|
|
|
|
|
0
|
return Ubic::Settings::ConfigFile->read($file); |
26
|
|
|
|
|
|
|
} |
27
|
23
|
|
|
|
|
73
|
return {}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _env_settings { |
31
|
|
|
|
|
|
|
return { |
32
|
|
|
|
|
|
|
($ENV{UBIC_SERVICE_DIR} ? (service_dir => $ENV{UBIC_SERVICE_DIR}) : ()), |
33
|
|
|
|
|
|
|
($ENV{UBIC_DIR} ? (data_dir => $ENV{UBIC_DIR}) : ()), |
34
|
23
|
50
|
|
23
|
|
235
|
($ENV{UBIC_DEFAULT_USER} ? (default_user => $ENV{UBIC_DEFAULT_USER}) : ()), |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _load { |
39
|
141
|
100
|
|
141
|
|
660
|
return $settings if $settings; |
40
|
|
|
|
|
|
|
|
41
|
23
|
|
|
|
|
100
|
my $file_settings = _file_settings; |
42
|
23
|
|
|
|
|
55
|
my $env_settings = _env_settings; |
43
|
|
|
|
|
|
|
|
44
|
23
|
|
|
|
|
111
|
$settings = { |
45
|
|
|
|
|
|
|
%$file_settings, |
46
|
|
|
|
|
|
|
%$env_settings, |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
23
|
50
|
|
|
|
433
|
unless (keys %$settings) { |
50
|
0
|
|
|
|
|
0
|
die "ubic is not configured, run 'ubic-admin setup' first\n"; |
51
|
|
|
|
|
|
|
} |
52
|
23
|
|
|
|
|
68
|
for (qw/ service_dir data_dir default_user /) { |
53
|
69
|
50
|
|
|
|
155
|
unless (defined $settings->{$_}) { |
54
|
0
|
|
|
|
|
0
|
die "incomplete ubic configuration, setting '$_' is not defined"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
23
|
|
|
|
|
116
|
return $settings; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub service_dir { |
62
|
71
|
|
|
71
|
1
|
4386
|
my ($class, $value) = validate_pos(@_, 1, 0); |
63
|
71
|
100
|
|
|
|
259
|
if (defined $value) { |
64
|
51
|
|
|
|
|
239
|
$ENV{UBIC_SERVICE_DIR} = $value; |
65
|
51
|
|
|
|
|
88
|
undef $settings; |
66
|
51
|
|
|
|
|
193
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
20
|
|
|
|
|
38
|
return _load->{service_dir}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub data_dir { |
72
|
71
|
|
|
71
|
1
|
808
|
my ($class, $value) = validate_pos(@_, 1, 0); |
73
|
71
|
100
|
|
|
|
413
|
if (defined $value) { |
74
|
51
|
|
|
|
|
1027
|
$ENV{UBIC_DIR} = $value; |
75
|
51
|
|
|
|
|
237
|
undef $settings; |
76
|
51
|
|
|
|
|
236
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
20
|
|
|
|
|
50
|
return _load->{data_dir}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub default_user { |
82
|
143
|
|
|
143
|
1
|
789
|
my ($class, $value) = validate_pos(@_, 1, 0); |
83
|
143
|
100
|
|
|
|
471
|
if (defined $value) { |
84
|
51
|
|
|
|
|
230
|
$ENV{UBIC_DEFAULT_USER} = $value; |
85
|
51
|
|
|
|
|
79
|
undef $settings; |
86
|
51
|
|
|
|
|
647
|
return; |
87
|
|
|
|
|
|
|
} |
88
|
92
|
|
|
|
|
197
|
return _load->{default_user}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub check_settings { |
92
|
9
|
|
|
9
|
1
|
28
|
_load; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |