]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Setup/Yaml.pm
Merge tag '3.20120202' into trail3-integrated
[git.ikiwiki.info.git] / IkiWiki / Setup / Yaml.pm
1 #!/usr/bin/perl
3 package IkiWiki::Setup::Yaml;
5 use warnings;
6 use strict;
7 use IkiWiki;
8 use Encode;
10 sub loaddump ($$) {
11         my $class=shift;
12         my $content=shift;
14         eval q{use YAML::XS};
15         die $@ if $@;
16         IkiWiki::Setup::merge(Load(encode_utf8($content)));
17 }
19 sub gendump ($@) {
20         my $class=shift;
21         
22         "# IkiWiki::Setup::Yaml - YAML formatted setup file",
23         "#",
24         (map { "# $_" } @_),
25         "#",
26         IkiWiki::Setup::commented_dump(\&dumpline, "")
27 }
30 sub dumpline ($$$$) {
31         my $key=shift;
32         my $value=shift;
33         my $type=shift;
34         my $prefix=shift;
35         
36         eval q{use YAML::XS};
37         die $@ if $@;
38         $YAML::XS::QuoteNumericStrings=0;
40         my $dump=decode_utf8(Dump({$key => $value}));
41         $dump=~s/^---\n//; # yaml header, we don't want
42         chomp $dump;
43         if (length $prefix) {
44                 $dump=join("\n", map { $prefix.$_ } split(/\n/, $dump));
45         }
46         return $dump;
47 }
49 1