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 | |
24 | ||
25 | ||
26 | =head1 METHODS | |
27 | ||
28 | =head2 extensions( ) | |
29 | ||
30 | return an array of valid extensions (C<yml>, C<yaml>). | |
31 | ||
32 | =cut | |
33 | ||
34 | sub extensions { | |
35 | return qw( yml yaml ); | |
36 | } | |
37 | ||
38 | =head2 load( $file ) | |
39 | ||
40 | Attempts to load C<$file> as a YAML file. | |
41 | ||
42 | =cut | |
43 | ||
44 | sub load { | |
45 | my $class = shift; | |
46 | my $file = shift; | |
47 | ||
c793253e | 48 | eval { require YAML::XS }; |
49 | unless ( $@ ) { | |
50 | return YAML::XS::LoadFile( $file ); | |
51 | } | |
52 | ||
9113afab | 53 | Carp::carp |
10a054f4 | 54 | 'Use of YAML::Syck or YAML to parse config files is DEPRECATED. ' |
55 | . 'Please install YAML::XS for proper YAML support'; | |
9113afab | 56 | |
48e4a267 | 57 | eval { require YAML::Syck; YAML::Syck->VERSION( '0.70' ) }; |
d49610ab | 58 | unless ( $@ ) { |
f0e3c221 | 59 | open( my $fh, $file ) or die $!; |
60 | my $content = do { local $/; <$fh> }; | |
61 | close $fh; | |
62 | return YAML::Syck::Load( $content ); | |
63 | } | |
d49610ab | 64 | |
65 | require YAML; | |
66 | return YAML::LoadFile( $file ); | |
f0e3c221 | 67 | } |
68 | ||
dcfb1d1d | 69 | =head2 requires_any_of( ) |
72628dc7 | 70 | |
9113afab | 71 | Specifies that this modules requires one of L<YAML::XS>, L<YAML::Syck> (0.70) or |
72 | L<YAML> in order to work. | |
72628dc7 | 73 | |
74 | =cut | |
75 | ||
c793253e | 76 | sub requires_any_of { 'YAML::XS', [ 'YAML::Syck', '0.70' ], 'YAML' } |
72628dc7 | 77 | |
f0e3c221 | 78 | =head1 AUTHOR |
79 | ||
a918b0b8 | 80 | Brian Cassidy E<lt>bricas@cpan.orgE<gt> |
f0e3c221 | 81 | |
82 | =head1 COPYRIGHT AND LICENSE | |
83 | ||
c793253e | 84 | Copyright 2006-2009 by Brian Cassidy |
f0e3c221 | 85 | |
86 | This library is free software; you can redistribute it and/or modify | |
87 | it under the same terms as Perl itself. | |
88 | ||
89 | =head1 SEE ALSO | |
90 | ||
91 | =over 4 | |
92 | ||
93 | =item * L<Catalyst> | |
94 | ||
95 | =item * L<Config::Any> | |
96 | ||
9113afab | 97 | =item * L<YAML::XS> |
98 | ||
f0e3c221 | 99 | =item * L<YAML> |
100 | ||
101 | =item * L<YAML::Syck> | |
102 | ||
103 | =back | |
104 | ||
105 | =cut | |
106 | ||
107 | 1; |