X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FYAML.pm;fp=SL%2FYAML.pm;h=bfccfba80e1e3143b13724dce854988406f03067;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hp=0000000000000000000000000000000000000000;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44;p=kivitendo-erp.git diff --git a/SL/YAML.pm b/SL/YAML.pm new file mode 100644 index 000000000..bfccfba80 --- /dev/null +++ b/SL/YAML.pm @@ -0,0 +1,60 @@ +package SL::YAML; + +use strict; +use warnings; + +sub _choose_yaml_module { + return 'YAML::XS' if $INC{'YAML/XS.pm'}; + return 'YAML' if $INC{'YAML.pm'}; + + my @err; + + return 'YAML::XS' if eval { require YAML::XS; 1; }; + push @err, "Error loading YAML::XS: $@"; + + return 'YAML' if eval { require YAML; 1; }; + push @err, "Error loading YAML: $@"; + + die join("\n", "Couldn't load a YAML module:", @err); +} + +BEGIN { + our $YAML_Class = _choose_yaml_module(); + $YAML_Class->import(qw(Dump Load DumpFile LoadFile)); +} + +sub YAML { our $YAML_Class } + +1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::YAML - A thin wrapper around YAML::XS and YAML + +=head1 SYNOPSIS + + use SL::YAML; + + my $menu_data = SL::YAML::LoadFile("menus/user/00-erp.yml"); + +=head1 OVERVIEW + +This is a thin wrapper around the YAML::XS and YAML modules. It'll +prefer loading YAML::XS if that's found and will fallback to YAML +otherwise. It only provides the four functions C, C, +C and C — just enough to get by for kivitendo. + +The functions are direct imports from the imported module. Please see +the documentation for YAML::XS or YAML for details. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut