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