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