line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojar::Config; |
2
|
3
|
|
|
3
|
|
28721
|
use Mojo::Base -base; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
41
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = 0.042; |
5
|
|
|
|
|
|
|
# Adapted from Mojolicious::Plugin::Config (3.57) |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
537
|
use Carp 'croak'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
148
|
|
8
|
3
|
|
|
3
|
|
969
|
use Mojo::File 'path'; |
|
3
|
|
|
|
|
195743
|
|
|
3
|
|
|
|
|
167
|
|
9
|
3
|
|
|
3
|
|
19
|
use Mojo::Util 'decode'; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
762
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub load { |
12
|
2
|
|
|
2
|
1
|
3234
|
my ($self, $file, %param) = @_; |
13
|
2
|
50
|
|
|
|
8
|
$param{log}->debug(sprintf 'Reading config file (%s)', $file) if $param{log}; |
14
|
2
|
50
|
33
|
|
|
58
|
croak "Failed to find file ($file)" unless -f $file or -l $file; |
15
|
2
|
|
|
|
|
10
|
my $content = decode 'UTF-8', path($file)->slurp; |
16
|
2
|
|
|
|
|
646
|
return $self->parse(\$content, %param); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub parse { |
20
|
2
|
|
|
2
|
1
|
1353
|
my ($self, $content_ref, %param) = @_; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Run Perl code |
23
|
2
|
|
|
1
|
|
180
|
my $config = eval sprintf '%s%s%s', 'package Mojar::Config::Sandbox;', |
|
1
|
|
|
1
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
24
|
|
|
|
|
|
|
'use strict;', $$content_ref; |
25
|
2
|
0
|
33
|
|
|
8
|
croak qq{Failed to load configuration from file: $@} if not $config and $@; |
26
|
2
|
50
|
|
|
|
7
|
croak qq{Config file did not return a hash reference.\n} |
27
|
|
|
|
|
|
|
unless ref $config eq 'HASH'; |
28
|
2
|
50
|
|
|
|
5
|
$param{log}->debug('Config content successfully read') if $param{log}; |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
10
|
return $config; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
__END__ |