epic-ts
[kivitendo-erp.git] / modules / override / YAML / Any.pm
1 use strict; use warnings;
2 package YAML::Any;
3 our $VERSION = '1.14';
4
5 use Exporter ();
6
7 @YAML::Any::ISA       = 'Exporter';
8 @YAML::Any::EXPORT    = qw(Dump Load);
9 @YAML::Any::EXPORT_OK = qw(DumpFile LoadFile);
10
11 my @dump_options = qw(
12     UseCode
13     DumpCode
14     SpecVersion
15     Indent
16     UseHeader
17     UseVersion
18     SortKeys
19     AnchorPrefix
20     UseBlock
21     UseFold
22     CompressSeries
23     InlineSeries
24     UseAliases
25     Purity
26     Stringify
27 );
28
29 my @load_options = qw(
30     UseCode
31     LoadCode
32 );
33
34 my @implementations = qw(
35     YAML::XS
36     YAML::Syck
37     YAML::Old
38     YAML
39     YAML::Tiny
40 );
41
42 sub import {
43     __PACKAGE__->implementation;
44     goto &Exporter::import;
45 }
46
47 sub Dump {
48     no strict 'refs';
49     no warnings 'once';
50     my $implementation = __PACKAGE__->implementation;
51     for my $option (@dump_options) {
52         my $var = "$implementation\::$option";
53         my $value = $$var;
54         local $$var;
55         $$var = defined $value ? $value : ${"YAML::$option"};
56     }
57     return &{"$implementation\::Dump"}(@_);
58 }
59
60 sub DumpFile {
61     no strict 'refs';
62     no warnings 'once';
63     my $implementation = __PACKAGE__->implementation;
64     for my $option (@dump_options) {
65         my $var = "$implementation\::$option";
66         my $value = $$var;
67         local $$var;
68         $$var = defined $value ? $value : ${"YAML::$option"};
69     }
70     return &{"$implementation\::DumpFile"}(@_);
71 }
72
73 sub Load {
74     no strict 'refs';
75     no warnings 'once';
76     my $implementation = __PACKAGE__->implementation;
77     for my $option (@load_options) {
78         my $var = "$implementation\::$option";
79         my $value = $$var;
80         local $$var;
81         $$var = defined $value ? $value : ${"YAML::$option"};
82     }
83     return &{"$implementation\::Load"}(@_);
84 }
85
86 sub LoadFile {
87     no strict 'refs';
88     no warnings 'once';
89     my $implementation = __PACKAGE__->implementation;
90     for my $option (@load_options) {
91         my $var = "$implementation\::$option";
92         my $value = $$var;
93         local $$var;
94         $$var = defined $value ? $value : ${"YAML::$option"};
95     }
96     return &{"$implementation\::LoadFile"}(@_);
97 }
98
99 sub order {
100     return @YAML::Any::_TEST_ORDER
101         if @YAML::Any::_TEST_ORDER;
102     return @implementations;
103 }
104
105 sub implementation {
106     my @order = __PACKAGE__->order;
107     for my $module (@order) {
108         my $path = $module;
109         $path =~ s/::/\//g;
110         $path .= '.pm';
111         return $module if exists $INC{$path};
112         eval "require $module; 1" and return $module;
113     }
114     croak("YAML::Any couldn't find any of these YAML implementations: @order");
115 }
116
117 sub croak {
118     require Carp;
119     Carp::croak(@_);
120 }
121
122 1;