refactor _load(). fix an issue with use_ext => 0. use_ext now on by default. throw...
[p5sagit/Config-Any.git] / lib / Config / Any / YAML.pm
CommitLineData
f0e3c221 1package Config::Any::YAML;
2
3use strict;
4use warnings;
5
6=head1 NAME
7
8Config::Any::YAML - Load YAML config files
9
10=head1 DESCRIPTION
11
12Loads 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
26return an array of valid extensions (C<yml>, C<yaml>).
27
28=cut
29
30sub extensions {
31 return qw( yml yaml );
32}
33
34=head2 load( $file )
35
36Attempts to load C<$file> as a YAML file.
37
38=cut
39
40sub load {
41 my $class = shift;
42 my $file = shift;
43
44 eval { require YAML::Syck; };
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
57=head1 AUTHOR
58
a918b0b8 59Brian Cassidy E<lt>bricas@cpan.orgE<gt>
f0e3c221 60
61=head1 COPYRIGHT AND LICENSE
62
a918b0b8 63Copyright 2007 by Brian Cassidy
f0e3c221 64
65This library is free software; you can redistribute it and/or modify
66it under the same terms as Perl itself.
67
68=head1 SEE ALSO
69
70=over 4
71
72=item * L<Catalyst>
73
74=item * L<Config::Any>
75
76=item * L<YAML>
77
78=item * L<YAML::Syck>
79
80=back
81
82=cut
83
841;