line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim: ai et sw=4 |
2
|
1
|
|
|
1
|
|
1938
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
4
|
|
|
|
|
|
|
package Mojolicious::Plugin::YamlConfig; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use base 'Mojolicious::Plugin::JSONConfig'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
618
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.2.4'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
3
|
|
|
3
|
1
|
35100
|
my ( $self, $app, $conf ) = @_; |
12
|
3
|
|
50
|
|
|
15
|
$conf ||= {}; |
13
|
3
|
|
|
|
|
11
|
$conf->{ext} = 'yaml'; |
14
|
3
|
|
50
|
|
|
37
|
$conf->{class} ||= $ENV{MOJO_YAML} || 'YAML::Tiny'; |
|
|
|
33
|
|
|
|
|
15
|
3
|
|
|
|
|
29
|
$self->{class} = $conf->{class}; |
16
|
3
|
|
|
|
|
11
|
my @supported = qw(YAML YAML::XS YAML::Tiny YAML::Old YAML::PP); |
17
|
3
|
50
|
|
|
|
8
|
unless ( grep { $conf->{class} eq $_ } @supported) { |
|
15
|
|
|
|
|
40
|
|
18
|
0
|
|
|
|
|
0
|
warn("$conf->{class} is not supported, use at your own risk"); |
19
|
|
|
|
|
|
|
} |
20
|
3
|
|
|
|
|
16
|
return $self->SUPER::register( $app, $conf ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub parse { |
24
|
1
|
|
|
1
|
1
|
572
|
my ($self, $content, $file, $conf, $app) = @_; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
4
|
my $class = $self->{class}; |
27
|
1
|
50
|
|
|
|
77
|
eval "require $class; 1" || die($@); |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
8
|
my ($config,$error); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Render |
32
|
1
|
|
|
|
|
21
|
$content = $self->render($content, $file, $conf, $app); |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
1929
|
my @broken = qw(YAML YAML::Old YAML::Tiny YAML::PP); |
35
|
1
|
50
|
|
|
|
5
|
unless (grep { $class eq $_ } @broken) { |
|
4
|
|
|
|
|
13
|
|
36
|
|
|
|
|
|
|
# they are broken *sigh* |
37
|
0
|
|
|
|
|
0
|
$content = Encode::encode('UTF-8', $content); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
66
|
$config = eval $class.'::Load($content)'; |
41
|
1
|
50
|
|
|
|
492
|
if($@) { |
42
|
0
|
|
|
|
|
0
|
$error = $@; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
50
|
33
|
|
|
6
|
die qq/Couldn't parse config "$file": $error/ if !$config && $error; |
46
|
1
|
50
|
33
|
|
|
9
|
die qq/Invalid config "$file"./ if !$config || ref $config ne 'HASH'; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
8
|
return $config; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
__END__ |