Commit | Line | Data |
f0e3c221 |
1 | package Config::Any::YAML; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | =head1 NAME |
7 | |
8 | Config::Any::YAML - Load YAML config files |
9 | |
10 | =head1 DESCRIPTION |
11 | |
12 | Loads YAML files. Example: |
13 | |
14 | --- |
15 | name: TestApp |
16 | Controller::Foo: |
17 | foo: bar |
18 | Model::Baz: |
19 | qux: xyzzy |
20 | |
21 | |
22 | =head1 METHODS |
23 | |
24 | =head2 extensions( ) |
25 | |
26 | return an array of valid extensions (C<yml>, C<yaml>). |
27 | |
28 | =cut |
29 | |
30 | sub extensions { |
31 | return qw( yml yaml ); |
32 | } |
33 | |
34 | =head2 load( $file ) |
35 | |
36 | Attempts to load C<$file> as a YAML file. |
37 | |
38 | =cut |
39 | |
40 | sub load { |
41 | my $class = shift; |
42 | my $file = shift; |
43 | |
48e4a267 |
44 | eval { require YAML::Syck; YAML::Syck->VERSION( '0.70' ) }; |
92a04e78 |
45 | if ( $@ ) { |
f0e3c221 |
46 | require YAML; |
47 | return YAML::LoadFile( $file ); |
48 | } |
49 | else { |
50 | open( my $fh, $file ) or die $!; |
51 | my $content = do { local $/; <$fh> }; |
52 | close $fh; |
53 | return YAML::Syck::Load( $content ); |
54 | } |
55 | } |
56 | |
72628dc7 |
57 | =head2 is_supported( ) |
58 | |
59 | Returns true if either L<YAML::Syck> or L<YAML> is available. |
60 | |
61 | =cut |
62 | |
63 | sub is_supported { |
06fb16e2 |
64 | eval { require YAML::Syck; YAML::Syck->VERSION( '0.70' ) }; |
72628dc7 |
65 | return 1 unless $@; |
66 | eval { require YAML; }; |
67 | return $@ ? 0 : 1; |
68 | } |
69 | |
f0e3c221 |
70 | =head1 AUTHOR |
71 | |
a918b0b8 |
72 | Brian Cassidy E<lt>bricas@cpan.orgE<gt> |
f0e3c221 |
73 | |
74 | =head1 COPYRIGHT AND LICENSE |
75 | |
a918b0b8 |
76 | Copyright 2007 by Brian Cassidy |
f0e3c221 |
77 | |
78 | This library is free software; you can redistribute it and/or modify |
79 | it under the same terms as Perl itself. |
80 | |
81 | =head1 SEE ALSO |
82 | |
83 | =over 4 |
84 | |
85 | =item * L<Catalyst> |
86 | |
87 | =item * L<Config::Any> |
88 | |
89 | =item * L<YAML> |
90 | |
91 | =item * L<YAML::Syck> |
92 | |
93 | =back |
94 | |
95 | =cut |
96 | |
97 | 1; |