File Coverage

File:lib/OpenAPI/Config.pm
Coverage:76.0%

linestmtbrancondsubpodtimecode
1package OpenAPI::Config;
2
3
25
25
25
195
74
216
use strict;
4
25
25
25
242
76
204
use warnings;
5
6
25
25
25
424
94
361
use FindBin;
7
25
25
25
309
96
327
use Config::Simple;
8
25
25
25
345
98
361
use Hash::Merge;
9
10sub init {
11
49
0
355
    my ($class, $root_path) = @_;
12
49
479
    $root_path ||= "$FindBin::Bin/..";
13
49
325
    my $path = "$root_path/etc/openapi.conf";
14
49
552
    my $config = new Config::Simple($path) or
15        die "Cannot open config file $path\n";
16
49
826
    my $default_vars = $config->vars;
17
49
256
    $path = "$root_path/etc/site_openapi.conf";
18
49
511
    $config = new Config::Simple($path) or
19        die "Cannot open config file $path\n";
20
49
128
    my $site_vars = $config->vars;
21
49
371
    my $vars = Hash::Merge::merge($site_vars, $default_vars);
22
49
375
    my $cmd = $ENV{OPENAPI_COMMAND};
23
49
143
    my $do_echo;
24
49
0
421
0
    if ($cmd and $cmd eq 'start') { $do_echo = 1; }
25
49
552
    while (my ($key, $val) = each %$vars) {
26
686
3900
        $val = '' if !defined $val;
27
686
3022
        warn "$key=$val\n" if $do_echo;
28
686
3137
        $OpenAPI::Config ||= {};
29
686
8073
        $OpenAPI::Config{$key} = $val;
30    }
31    ### $vars
32
49
528
    if (!$OpenAPI::Config{'backend.type'}) {
33
0
0
        warn "backend.type=Pg\n" if $do_echo;
34
0
0
        $OpenAPI::Config{'backend.type'} = 'Pg';
35    }
36
49
370
    if (!$OpenAPI::Config{'cache.type'}) {
37
0
0
        warn "backend.type=mmap\n" if $do_echo;
38
0
0
        $OpenAPI::Config{'cache.type'} = 'mmap';
39    }
40
49
284
    $OpenAPI::Limits::RECORD_LIMIT = $OpenAPI::Config{'frontend.row_limit'};
41
49
278
    $OpenAPI::Limits::COLUMN_LIMIT = $OpenAPI::Config{'frontend.column_limit'};
42
49
269
    $OpenAPI::Limits::MODEL_LIMIT = $OpenAPI::Config{'frontend.model_limit'};
43
49
164
    $OpenAPI::Limits::POST_LEN_LIMIT = $OpenAPI::Config{'frontend.post_len_limit'};
44}
45
461;
47