Commit | Line | Data |
---|---|---|
f0e3c221 | 1 | package Config::Any::YAML; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
dcfb1d1d | 6 | use base 'Config::Any::Base'; |
7 | ||
9113afab | 8 | use Carp (); |
9 | ||
f0e3c221 | 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 | |
f0e3c221 | 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 | ||
2ff1869f | 47 | if (eval { require YAML::XS; 1 }) { |
c793253e | 48 | return YAML::XS::LoadFile( $file ); |
49 | } | |
2ff1869f | 50 | elsif ($] > 5.008008 && eval { require YAML::Syck; YAML::Syck->VERSION(0.70) } ) { |
f0e3c221 | 51 | open( my $fh, $file ) or die $!; |
52 | my $content = do { local $/; <$fh> }; | |
53 | close $fh; | |
54 | return YAML::Syck::Load( $content ); | |
55 | } | |
d49610ab | 56 | |
57 | require YAML; | |
58 | return YAML::LoadFile( $file ); | |
f0e3c221 | 59 | } |
60 | ||
dcfb1d1d | 61 | =head2 requires_any_of( ) |
72628dc7 | 62 | |
9113afab | 63 | Specifies that this modules requires one of L<YAML::XS>, L<YAML::Syck> (0.70) or |
64 | L<YAML> in order to work. | |
72628dc7 | 65 | |
66 | =cut | |
67 | ||
2ff1869f | 68 | sub requires_any_of { |
69 | 'YAML::XS', ( $] > 5.008008 ? [ 'YAML::Syck', '0.70' ] : ()), 'YAML'; | |
70 | } | |
72628dc7 | 71 | |
f0e3c221 | 72 | =head1 AUTHOR |
73 | ||
a918b0b8 | 74 | Brian Cassidy E<lt>bricas@cpan.orgE<gt> |
f0e3c221 | 75 | |
76 | =head1 COPYRIGHT AND LICENSE | |
77 | ||
3d43e104 | 78 | Copyright 2006-2016 by Brian Cassidy |
f0e3c221 | 79 | |
80 | This library is free software; you can redistribute it and/or modify | |
19f6cb63 | 81 | it under the same terms as Perl itself. |
f0e3c221 | 82 | |
83 | =head1 SEE ALSO | |
84 | ||
19f6cb63 | 85 | =over 4 |
f0e3c221 | 86 | |
87 | =item * L<Catalyst> | |
88 | ||
89 | =item * L<Config::Any> | |
90 | ||
9113afab | 91 | =item * L<YAML::XS> |
92 | ||
f0e3c221 | 93 | =item * L<YAML> |
94 | ||
95 | =item * L<YAML::Syck> | |
96 | ||
97 | =back | |
98 | ||
99 | =cut | |
100 | ||
101 | 1; |