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