white space cleanups
[p5sagit/Config-Any.git] / lib / Config / Any / YAML.pm
1 package Config::Any::YAML;
2
3 use strict;
4 use warnings;
5
6 use base 'Config::Any::Base';
7
8 use Carp ();
9
10 =head1 NAME
11
12 Config::Any::YAML - Load YAML config files
13
14 =head1 DESCRIPTION
15
16 Loads YAML files. Example:
17
18     ---
19     name: TestApp
20     Controller::Foo:
21         foo: bar
22     Model::Baz:
23         qux: xyzzy
24
25 =head1 METHODS
26
27 =head2 extensions( )
28
29 return an array of valid extensions (C<yml>, C<yaml>).
30
31 =cut
32
33 sub extensions {
34     return qw( yml yaml );
35 }
36
37 =head2 load( $file )
38
39 Attempts to load C<$file> as a YAML file.
40
41 =cut
42
43 sub load {
44     my $class = shift;
45     my $file  = shift;
46
47     if (eval { require YAML::XS; 1 }) {
48         return YAML::XS::LoadFile( $file );
49     }
50     elsif ($] > 5.008008 && eval { require YAML::Syck; YAML::Syck->VERSION(0.70) } ) {
51         open( my $fh, $file ) or die $!;
52         my $content = do { local $/; <$fh> };
53         close $fh;
54         return YAML::Syck::Load( $content );
55     }
56
57     require YAML;
58     return YAML::LoadFile( $file );
59 }
60
61 =head2 requires_any_of( )
62
63 Specifies that this modules requires one of L<YAML::XS>, L<YAML::Syck> (0.70) or
64 L<YAML> in order to work.
65
66 =cut
67
68 sub requires_any_of {
69     'YAML::XS', ( $] > 5.008008 ? [ 'YAML::Syck', '0.70' ] : ()), 'YAML';
70 }
71
72 =head1 AUTHOR
73
74 Brian Cassidy E<lt>bricas@cpan.orgE<gt>
75
76 =head1 COPYRIGHT AND LICENSE
77
78 Copyright 2006-2016 by Brian Cassidy
79
80 This library is free software; you can redistribute it and/or modify
81 it under the same terms as Perl itself.
82
83 =head1 SEE ALSO
84
85 =over 4
86
87 =item * L<Catalyst>
88
89 =item * L<Config::Any>
90
91 =item * L<YAML::XS>
92
93 =item * L<YAML>
94
95 =item * L<YAML::Syck>
96
97 =back
98
99 =cut
100
101 1;