line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::ServiceLoader::Ext::ini; |
2
|
|
|
|
|
|
|
$Ubic::ServiceLoader::Ext::ini::VERSION = '1.60'; |
3
|
|
|
|
|
|
|
# ABSTRACT: loader for ini-style configs |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
23394
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
62
|
|
7
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
59
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
9
|
use parent qw( Ubic::ServiceLoader::Base ); |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
9
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
1163
|
use Config::Tiny; |
|
3
|
|
|
|
|
2025
|
|
|
3
|
|
|
|
|
1255
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
2
|
|
|
2
|
1
|
9
|
my $class = shift; |
15
|
2
|
|
|
|
|
7
|
return bless {} => $class; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub load { |
19
|
6
|
|
|
6
|
1
|
6
|
my $self = shift; |
20
|
6
|
|
|
|
|
5
|
my ($file) = @_; |
21
|
|
|
|
|
|
|
|
22
|
6
|
|
|
|
|
20
|
my $config = Config::Tiny->read($file); |
23
|
6
|
100
|
|
|
|
585
|
unless ($config) { |
24
|
1
|
|
|
|
|
4
|
die Config::Tiny->errstr; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
5
|
|
|
|
|
8
|
my $root_section = delete $config->{_}; |
28
|
5
|
|
100
|
|
|
17
|
my $module = delete $root_section->{module} || 'Ubic::Service::SimpleDaemon'; |
29
|
5
|
100
|
|
|
|
11
|
if (keys %$root_section) { |
30
|
1
|
|
|
|
|
11
|
die "Unknown option ".join(', ', keys %$root_section)." in file $file"; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
5
|
my $options = delete $config->{options}; |
34
|
4
|
100
|
|
|
|
9
|
if (keys %$config) { |
35
|
1
|
|
|
|
|
13
|
die "Unknown section ".join(', ', keys %$config)." in file $file"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
3
|
50
|
|
|
|
11
|
$module =~ /^[\w:]+$/ or die "Invalid module name '$module'"; |
39
|
3
|
|
|
|
|
143
|
eval "require $module"; # TODO - Class::Load? |
40
|
3
|
50
|
|
|
|
12
|
if ($@) { |
41
|
0
|
|
|
|
|
0
|
die $@; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
4
|
my @options = (); |
45
|
3
|
50
|
|
|
|
8
|
@options = ($options) if $options; # some modules can have zero options, I guess |
46
|
3
|
|
|
|
|
12
|
return $module->new(@options); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
__END__ |