epic-s6ts
[kivitendo-erp.git] / SL / YAML.pm
1 package SL::YAML;
2
3 use strict;
4 use warnings;
5
6 sub _choose_yaml_module {
7   return 'YAML::XS' if $INC{'YAML/XS.pm'};
8   return 'YAML'     if $INC{'YAML.pm'};
9
10   my @err;
11
12   return 'YAML::XS' if eval { require YAML::XS; 1; };
13   push @err, "Error loading YAML::XS: $@";
14
15   return 'YAML' if eval { require YAML; 1; };
16   push @err, "Error loading YAML: $@";
17
18   die join("\n", "Couldn't load a YAML module:", @err);
19 }
20
21 BEGIN {
22   our $YAML_Class = _choose_yaml_module();
23   $YAML_Class->import(qw(Dump Load DumpFile LoadFile));
24 }
25
26 sub YAML { our $YAML_Class }
27
28 1;
29
30 __END__
31
32 =pod
33
34 =encoding utf8
35
36 =head1 NAME
37
38 SL::YAML - A thin wrapper around YAML::XS and YAML
39
40 =head1 SYNOPSIS
41
42     use SL::YAML;
43
44     my $menu_data = SL::YAML::LoadFile("menus/user/00-erp.yml");
45
46 =head1 OVERVIEW
47
48 This is a thin wrapper around the YAML::XS and YAML modules. It'll
49 prefer loading YAML::XS if that's found and will fallback to YAML
50 otherwise. It only provides the four functions C<Dump>, C<Load>,
51 C<DumpFile> and C<LoadFile> — just enough to get by for kivitendo.
52
53 The functions are direct imports from the imported module. Please see
54 the documentation for YAML::XS or YAML for details.
55
56 =head1 AUTHOR
57
58 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
59
60 =cut