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