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