File Coverage

blib/lib/Catalyst/Plugin/Config/Perl.pm
Criterion Covered Total %
statement 37 37 100.0
branch 9 12 75.0
condition 3 5 60.0
subroutine 5 5 100.0
pod 2 2 100.0
total 56 61 91.8


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::Config::Perl;
2 5     5   99521 use 5.012;
  5         25  
3 5     5   2312 use Config::MorePerl;
  5         116116  
  5         245  
4              
5             our $VERSION = '1.1.0';
6              
7 5     5   2187 use Class::Accessor::Inherited::XS inherited => [qw/cfg dev config_initial/];
  5         14535  
  5         25  
8              
9             sub setup {
10 4     4 1 1053359 my $class = shift;
11 4         31 my $initial_cfg = $class->config;
12 4         470 $class->config_initial($initial_cfg);
13 4         28 $class->cfg($initial_cfg);
14 4         25 $class->config_reload;
15 4         155 $class->next::method(@_);
16             }
17              
18             sub config_reload {
19 5   33 5 1 54884 my $class = ref($_[0]) || $_[0];
20             #my $start = Time::HiRes::time();
21 5         22 my $initial_cfg = $class->config_initial;
22 5   100     68 my $self_cfg = $initial_cfg->{'Plugin::Config::Perl'} || {};
23 5 100       74 $initial_cfg->{home} = Path::Class::Dir->new($initial_cfg->{home}) unless ref $initial_cfg->{home};
24            
25 5         340 my $conf_file;
26 5 100       22 if ($self_cfg->{file}) {
27 2         11 $conf_file = $initial_cfg->{home}->file($self_cfg->{file});
28             } else {
29 3         18 my $local_file = $initial_cfg->{home}->file('local.conf');
30 3 100       419 if (-f $local_file) { $conf_file = $local_file }
  2         202  
31             else {
32 1         72 my $main_file = $initial_cfg->{home}->file('conf/'.lc($class).'.conf');
33 1 50       77 $conf_file = $main_file if -f $main_file;
34             }
35             }
36            
37 5 50       389 if ($conf_file) {
38 5         79 my $cfg = Config::MorePerl->process($conf_file, $initial_cfg);
39 5         7151 my $old = $class->setup_finished;
40 5         313 $class->setup_finished(0); # work around fucking and annoying Catalyst
41 5         138 $class->config($cfg);
42 5         751 $class->setup_finished($old);
43 5         97 $class->cfg($cfg);
44             }
45            
46 5         79 $class->dev($class->cfg->{dev});
47              
48             #print "ConfigSuite Init took ".((Time::HiRes::time() - $start)*1000)."\n";
49 5         47 my $sub = $class->can('finalize_config');
50 5 50       36 $sub->($class) if $sub;
51            
52 5         645 $class->dev($class->cfg->{dev});
53             }
54              
55             1;