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