Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / YAML / Any.pm
1 package YAML::Any;
2
3 use 5.005003;
4 use strict;
5 use Exporter ();
6
7 $YAML::Any::VERSION   = '0.70';
8 @YAML::Any::ISA       = 'Exporter';
9 @YAML::Any::EXPORT    = qw(Dump Load);
10 @YAML::Any::EXPORT_OK = qw(DumpFile LoadFile);
11
12 my @dump_options = qw(
13     UseCode
14     DumpCode
15     SpecVersion
16     Indent
17     UseHeader
18     UseVersion
19     SortKeys
20     AnchorPrefix
21     UseBlock
22     UseFold
23     CompressSeries
24     InlineSeries
25     UseAliases
26     Purity
27     Stringify
28 );
29
30 my @load_options = qw(
31     UseCode
32     LoadCode
33 );
34
35 my @implementations = qw(
36     YAML::XS
37     YAML::Syck
38     YAML::Old
39     YAML
40     YAML::Tiny
41 );
42
43 sub import {
44     __PACKAGE__->implementation;
45     goto &Exporter::import;
46 }
47
48 sub Dump {
49     no strict 'refs';
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     my $implementation = __PACKAGE__->implementation;
63     for my $option (@dump_options) {
64         my $var = "$implementation\::$option";
65         my $value = $$var;
66         local $$var;
67         $$var = defined $value ? $value : ${"YAML::$option"};
68     }
69     return &{"$implementation\::DumpFile"}(@_);
70 }
71
72 sub Load {
73     no strict 'refs';
74     my $implementation = __PACKAGE__->implementation;
75     for my $option (@load_options) {
76         my $var = "$implementation\::$option";
77         my $value = $$var;
78         local $$var;
79         $$var = defined $value ? $value : ${"YAML::$option"};
80     }
81     return &{"$implementation\::Load"}(@_);
82 }
83
84 sub LoadFile {
85     no strict 'refs';
86     my $implementation = __PACKAGE__->implementation;
87     for my $option (@load_options) {
88         my $var = "$implementation\::$option";
89         my $value = $$var;
90         local $$var;
91         $$var = defined $value ? $value : ${"YAML::$option"};
92     }
93     return &{"$implementation\::LoadFile"}(@_);
94 }
95
96 sub order {
97     return @YAML::Any::_TEST_ORDER
98         if defined @YAML::Any::_TEST_ORDER;
99     return @implementations;
100 }
101
102 sub implementation {
103     my @order = __PACKAGE__->order;
104     for my $module (@order) {
105         my $path = $module;
106         $path =~ s/::/\//g;
107         $path .= '.pm';
108         return $module if exists $INC{$path};
109         eval "require $module; 1" and return $module;
110     }
111     croak("YAML::Any couldn't find any of these YAML implementations: @order");
112 }
113
114 sub croak {
115     require Carp;
116     Carp::Croak(@_);
117 }
118
119 1;
120
121 =head1 NAME
122
123 YAML::Any - Pick a YAML implementation and use it.
124
125 =head1 SYNOPSIS
126
127     use YAML::Any;
128     $YAML::Indent = 3;
129     my $yaml = Dump(@objects);
130
131 =head1 DESCRIPTION
132
133 There are several YAML implementations that support the Dump/Load API.
134 This module selects the best one available and uses it.
135
136 =head1 ORDER
137
138 Currently, YAML::Any will choose the first one of these YAML
139 implementations that is installed on your system:
140
141     YAML::XS
142     YAML::Syck
143     YAML::Old
144     YAML
145     YAML::Tiny
146
147 =head1 OPTIONS
148
149 If you specify an option like:
150
151     $YAML::Indent = 4;
152
153 And YAML::Any is using YAML::XS, it will use the proper variable:
154 $YAML::XS::Indent.
155
156 =head1 SUBROUTINES
157
158 Like all the YAML modules that YAML::Any uses, the following subroutines
159 are exported by default:
160
161     Dump
162     Load
163
164 and the following subroutines are exportable by request:
165
166     DumpFile
167     LoadFile
168
169 =head1 METHODS
170
171 YAML::Any provides the following class methods.
172
173 =over
174
175 =item YAML::Any->order;
176
177 This method returns a list of the current possible implementations that
178 YAML::Any will search for.
179
180 =item YAML::Any->implementation;
181
182 This method returns the implementation the YAML::Any will use. This
183 result is obtained by finding the first member of YAML::Any->order that
184 is either already loaded in C<%INC> or that can be loaded using
185 C<require>. If no implementation is found, an error will be thrown.
186
187 =back
188
189 =head1 AUTHOR
190
191 Ingy döt Net <ingy@cpan.org>
192
193 =head1 COPYRIGHT
194
195 Copyright (c) 2008. Ingy döt Net.
196
197 This program is free software; you can redistribute it and/or modify it
198 under the same terms as Perl itself.
199
200 See L<http://www.perl.com/perl/misc/Artistic.html>
201
202 =cut