File Coverage

blib/lib/Config/Any/General.pm
Criterion Covered Total %
statement 13 19 68.4
branch n/a
condition n/a
subroutine 4 5 80.0
pod 2 2 100.0
total 19 26 73.1


line stmt bran cond sub pod time code
1             package Config::Any::General;
2              
3 5     5   92 use strict;
  5         80  
  5         82  
4 5     5   80 use warnings;
  5         46  
  5         946  
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 12     12 1 169     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 8     8 1 111     my $class = shift;
42 8         74     my $file = shift;
43              
44             # work around bug (?) in Config::General
45             # return if $class->_test_perl($file);
46              
47 8         202     require Config::General;
48 8         146     my $configfile = Config::General->new( $file );
49 8         102     my $config = { $configfile->getall };
50                 
51 8         441     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              
60             sub _test_perl {
61 0     0         my ($class, $file) = @_;
62 0               my $is_perl_src;
63 0               eval { $is_perl_src = do "$file"; };
  0            
64 0               delete $INC{$file}; # so we don't screw stuff later on
65 0               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            
86             Copyright 2006 by Brian Cassidy
87            
88             Portions Copyright 2006 Portugal Telecom
89            
90             This library is free software; you can redistribute it and/or modify
91             it 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              
107             1;
108              
109