line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# vim: ai et sw=4 |
2
|
1
|
|
|
1
|
|
2079
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
4
|
|
|
|
|
|
|
package Mojolicious::Plugin::YamlConfig; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'Mojolicious::Plugin::JSONConfig'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
670
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.2.3'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
3
|
|
|
3
|
1
|
36426
|
my ( $self, $app, $conf ) = @_; |
12
|
3
|
|
50
|
|
|
15
|
$conf ||= {}; |
13
|
3
|
|
|
|
|
12
|
$conf->{ext} = 'yaml'; |
14
|
3
|
|
50
|
|
|
35
|
$conf->{class} ||= $ENV{MOJO_YAML} || 'YAML::Tiny'; |
|
|
|
33
|
|
|
|
|
15
|
3
|
|
|
|
|
19
|
$self->{class} = $conf->{class}; |
16
|
3
|
|
|
|
|
12
|
my @supported = qw(YAML YAML::XS YAML::Tiny YAML::Old YAML::PP); |
17
|
3
|
50
|
|
|
|
7
|
unless ( grep { $conf->{class} eq $_ } @supported) { |
|
15
|
|
|
|
|
37
|
|
18
|
0
|
|
|
|
|
0
|
warn("$conf->{class} is not supported, use at your own risk"); |
19
|
|
|
|
|
|
|
} |
20
|
3
|
|
|
|
|
19
|
return $self->SUPER::register( $app, $conf ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub parse { |
24
|
1
|
|
|
1
|
1
|
609
|
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
|
|
|
|
|
6
|
my ($config,$error); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Render |
32
|
1
|
|
|
|
|
24
|
$content = $self->render($content, $file, $conf, $app); |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
2053
|
my @broken = qw(YAML YAML::Old YAML::Tiny YAML::PP); |
35
|
1
|
50
|
|
|
|
4
|
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
|
|
|
|
|
70
|
$config = eval $class.'::Load($content)'; |
41
|
1
|
50
|
|
|
|
537
|
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__ |