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   117404 use 5.012;
  5         32  
3 5     5   2519 use Panda::Config::Perl;
  5         100215  
  5         289  
4              
5             our $VERSION = '1.0.4';
6              
7 5     5   2655 use Class::Accessor::Inherited::XS inherited => [qw/cfg dev config_initial/];
  5         17278  
  5         29  
8              
9             sub setup {
10 4     4 1 1274100 my $class = shift;
11 4         34 my $initial_cfg = $class->config;
12 4         515 $class->config_initial($initial_cfg);
13 4         31 $class->cfg($initial_cfg);
14 4         39 $class->config_reload;
15 4         178 $class->next::method(@_);
16             }
17              
18             sub config_reload {
19 5   33 5 1 68581 my $class = ref($_[0]) || $_[0];
20             #my $start = Time::HiRes::time();
21 5         21 my $initial_cfg = $class->config_initial;
22 5   100     32 my $self_cfg = $initial_cfg->{'Plugin::Config::Perl'} || {};
23 5 100       83 $initial_cfg->{home} = Path::Class::Dir->new($initial_cfg->{home}) unless ref $initial_cfg->{home};
24            
25 5         373 my $conf_file;
26 5 100       26 if ($self_cfg->{file}) {
27 2         13 $conf_file = $initial_cfg->{home}->file($self_cfg->{file});
28             } else {
29 3         19 my $local_file = $initial_cfg->{home}->file('local.conf');
30 3 100       455 if (-f $local_file) { $conf_file = $local_file }
  2         268  
31             else {
32 1         86 my $main_file = $initial_cfg->{home}->file('conf/'.lc($class).'.conf');
33 1 50       98 $conf_file = $main_file if -f $main_file;
34             }
35             }
36            
37 5 50       442 if ($conf_file) {
38 5         90 my $cfg = Panda::Config::Perl->process($conf_file, $initial_cfg);
39 5         8561 my $old = $class->setup_finished;
40 5         371 $class->setup_finished(0); # work around fucking and annoying Catalyst
41 5         157 $class->config($cfg);
42 5         915 $class->setup_finished($old);
43 5         114 $class->cfg($cfg);
44             }
45            
46 5         95 $class->dev($class->cfg->{dev});
47              
48             #print "ConfigSuite Init took ".((Time::HiRes::time() - $start)*1000)."\n";
49 5         58 my $sub = $class->can('finalize_config');
50 5 50       44 $sub->($class) if $sub;
51            
52 5         484 $class->dev($class->cfg->{dev});
53             }
54              
55             1;