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