File Coverage

blib/lib/Catalyst/Plugin/Config/Perl.pm
Criterion Covered Total %
statement 41 41 100.0
branch 9 12 75.0
condition 3 5 60.0
subroutine 6 6 100.0
pod 0 2 0.0
total 59 66 89.3


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::Config::Perl;
2 5     5   24354 use 5.012;
  5         12  
  5         151  
3 5     5   2092 use Panda::Lib 'fclone';
  5         46939  
  5         141  
4 5     5   1761 use Panda::Config::Perl;
  5         4449  
  5         185  
5              
6             our $VERSION = '1.0.3';
7              
8 5     5   1855 use Class::Accessor::Inherited::XS inherited => [qw/cfg dev config_initial/];
  5         2832  
  5         31  
9              
10             sub setup {
11 4     4 0 577472 my $class = shift;
12 4         29 my $initial_cfg = $class->config;
13 4         375 $class->config_initial($initial_cfg);
14 4         26 $class->cfg($initial_cfg);
15 4         22 $class->config_reload;
16 4         30 $class->next::method(@_);
17             }
18              
19             sub config_reload {
20 5   33 5 0 41778 my $class = ref($_[0]) || $_[0];
21             #my $start = Time::HiRes::time();
22 5         16 my $initial_cfg = $class->config_initial;
23 5   100     30 my $self_cfg = $initial_cfg->{'Plugin::Config::Perl'} || {};
24 5 100       72 $initial_cfg->{home} = Path::Class::Dir->new($initial_cfg->{home}) unless ref $initial_cfg->{home};
25            
26 5         308 my $conf_file;
27 5 100       17 if ($self_cfg->{file}) {
28 2         10 $conf_file = $initial_cfg->{home}->file($self_cfg->{file});
29             } else {
30 3         20 my $local_file = $initial_cfg->{home}->file('local.conf');
31 3 100       631 if (-f $local_file) { $conf_file = $local_file }
  2         126  
32             else {
33 1         40 my $main_file = $initial_cfg->{home}->file('conf/'.lc($class).'.conf');
34 1 50       78 $conf_file = $main_file if -f $main_file;
35             }
36             }
37            
38 5 50       499 if ($conf_file) {
39 5         63 my $cfg = Panda::Config::Perl->process($conf_file, $initial_cfg);
40 5         2655 my $old = $class->setup_finished;
41 5         232 $class->setup_finished(0); # work around fucking and annoying Catalyst
42 5         98 $class->config($cfg);
43 5         499 $class->setup_finished($old);
44 5         64 $class->cfg($cfg);
45             }
46            
47 5         47 $class->dev($class->cfg->{dev});
48              
49             #print "ConfigSuite Init took ".((Time::HiRes::time() - $start)*1000)."\n";
50 5         48 my $sub = $class->can('finalize_config');
51 5 50       32 $sub->($class) if $sub;
52            
53 5         608 $class->dev($class->cfg->{dev});
54             }
55              
56             1;