git: Avoid adding files when committing, so as not to implicitly add files like recen...
[ikiwiki.git] / IkiWiki / Setup / Yaml.pm
blob904784728e0a0cbc6314cf26006010b5e5d25d8a
1 #!/usr/bin/perl
3 package IkiWiki::Setup::Yaml;
5 use warnings;
6 use strict;
7 use IkiWiki;
9 sub loaddump ($$) {
10 my $class=shift;
11 my $content=shift;
13 eval q{use YAML::Any};
14 eval q{use YAML} if $@;
15 die $@ if $@;
16 $YAML::Syck::ImplicitUnicode=1;
17 IkiWiki::Setup::merge(Load($content));
20 sub gendump ($@) {
21 my $class=shift;
23 "# IkiWiki::Setup::Yaml - YAML formatted setup file",
24 "#",
25 (map { "# $_" } @_),
26 "#",
27 IkiWiki::Setup::commented_dump(\&dumpline, "")
31 sub dumpline ($$$$) {
32 my $key=shift;
33 my $value=shift;
34 my $type=shift;
35 my $prefix=shift;
37 eval q{use YAML::Old};
38 eval q{use YAML} if $@;
39 die $@ if $@;
40 $YAML::UseHeader=0;
42 my $dump=Dump({$key => $value});
43 chomp $dump;
44 if (length $prefix) {
45 $dump=join("\n", map { $prefix.$_ } split(/\n/, $dump));
47 return $dump;