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