enable -ForceArray option by default for Config::General
[p5sagit/Config-Any.git] / lib / Config / Any / General.pm
CommitLineData
f0e3c221 1package Config::Any::General;
2
3use strict;
4use warnings;
5
dcfb1d1d 6use base 'Config::Any::Base';
7
f0e3c221 8=head1 NAME
9
10Config::Any::General - Load Config::General files
11
12=head1 DESCRIPTION
13
14Loads Config::General files. Example:
15
16 name = TestApp
17 <Component Controller::Foo>
18 foo bar
7adf5673 19 bar [ arrayref-value ]
f0e3c221 20 </Component>
21 <Model Baz>
22 qux xyzzy
23 </Model>
24
25=head1 METHODS
26
27=head2 extensions( )
28
29return an array of valid extensions (C<cnf>, C<conf>).
30
31=cut
32
33sub extensions {
34 return qw( cnf conf );
35}
36
37=head2 load( $file )
38
39Attempts to load C<$file> via Config::General.
40
41=cut
42
43sub load {
44 my $class = shift;
45 my $file = shift;
e0c0c283 46 my $args = shift || {};
f0e3c221 47
48 # work around bug (?) in Config::General
92a04e78 49 # return if $class->_test_perl($file);
f0e3c221 50
92a04e78 51 $args->{ -ConfigFile } = $file;
e0c0c283 52
7adf5673 53 $args->{ -ForceArray } = 1 unless exists $args->{ -ForceArray };
54
f0e3c221 55 require Config::General;
e0c0c283 56 my $configfile = Config::General->new( %$args );
f0e3c221 57 my $config = { $configfile->getall };
92a04e78 58
f0e3c221 59 return $config;
60}
61
62# this is a bit of a hack but necessary, because Config::General is *far* too lax
63# about what it will load -- specifically, it seems to be quite happy to load a Perl
64# config file (ie, a file which is valid Perl and creates a hashref) as if it were
65# an Apache-style configuration file, presumably due to laziness on the part of the
66# developer.
67
68sub _test_perl {
92a04e78 69 my ( $class, $file ) = @_;
f0e3c221 70 my $is_perl_src;
71 eval { $is_perl_src = do "$file"; };
92a04e78 72 delete $INC{ $file }; # so we don't screw stuff later on
f0e3c221 73 return defined $is_perl_src;
74}
75
dcfb1d1d 76=head2 requires_all_of( )
72628dc7 77
dcfb1d1d 78Specifies that this module requires L<Config::General> in order to work.
72628dc7 79
80=cut
81
dcfb1d1d 82sub requires_all_of { 'Config::General' }
72628dc7 83
f0e3c221 84=head1 AUTHOR
85
a918b0b8 86Brian Cassidy E<lt>bricas@cpan.orgE<gt>
f0e3c221 87
88=head1 CONTRIBUTORS
89
a918b0b8 90Joel Bernstein C<< <rataxis@cpan.org> >>
f0e3c221 91
92=head1 COPYRIGHT AND LICENSE
93
f07b7a17 94Copyright 2006-2010 by Brian Cassidy
f0e3c221 95
96Portions Copyright 2006 Portugal Telecom
97
98This library is free software; you can redistribute it and/or modify
99it under the same terms as Perl itself.
100
101=head1 SEE ALSO
102
103=over 4
104
105=item * L<Catalyst>
106
107=item * L<Config::Any>
108
109=item * L<Config::General>
110
111=back
112
113=cut
114
1151;
116