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 | |
f0e3c221 |
8 | =head1 NAME |
9 | |
10 | Config::Any::YAML - Load YAML config files |
11 | |
12 | =head1 DESCRIPTION |
13 | |
14 | Loads YAML files. Example: |
15 | |
16 | --- |
17 | name: TestApp |
18 | Controller::Foo: |
19 | foo: bar |
20 | Model::Baz: |
21 | qux: xyzzy |
22 | |
23 | |
24 | =head1 METHODS |
25 | |
26 | =head2 extensions( ) |
27 | |
28 | return an array of valid extensions (C<yml>, C<yaml>). |
29 | |
30 | =cut |
31 | |
32 | sub extensions { |
33 | return qw( yml yaml ); |
34 | } |
35 | |
36 | =head2 load( $file ) |
37 | |
38 | Attempts to load C<$file> as a YAML file. |
39 | |
40 | =cut |
41 | |
42 | sub load { |
43 | my $class = shift; |
44 | my $file = shift; |
45 | |
c793253e |
46 | eval { require YAML::XS }; |
47 | unless ( $@ ) { |
48 | return YAML::XS::LoadFile( $file ); |
49 | } |
50 | |
48e4a267 |
51 | eval { require YAML::Syck; YAML::Syck->VERSION( '0.70' ) }; |
d49610ab |
52 | unless ( $@ ) { |
f0e3c221 |
53 | open( my $fh, $file ) or die $!; |
54 | my $content = do { local $/; <$fh> }; |
55 | close $fh; |
56 | return YAML::Syck::Load( $content ); |
57 | } |
d49610ab |
58 | |
59 | require YAML; |
60 | return YAML::LoadFile( $file ); |
f0e3c221 |
61 | } |
62 | |
dcfb1d1d |
63 | =head2 requires_any_of( ) |
72628dc7 |
64 | |
dcfb1d1d |
65 | Specifies that this modules requires one of L<YAML::Syck> (0.70) or L<YAML> in |
66 | order to work. |
72628dc7 |
67 | |
68 | =cut |
69 | |
c793253e |
70 | sub requires_any_of { 'YAML::XS', [ 'YAML::Syck', '0.70' ], 'YAML' } |
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 | |
c793253e |
78 | Copyright 2006-2009 by Brian Cassidy |
f0e3c221 |
79 | |
80 | This library is free software; you can redistribute it and/or modify |
81 | it under the same terms as Perl itself. |
82 | |
83 | =head1 SEE ALSO |
84 | |
85 | =over 4 |
86 | |
87 | =item * L<Catalyst> |
88 | |
89 | =item * L<Config::Any> |
90 | |
91 | =item * L<YAML> |
92 | |
93 | =item * L<YAML::Syck> |
94 | |
95 | =back |
96 | |
97 | =cut |
98 | |
99 | 1; |