Config.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 52 CC 1 SCAR 6.9
CC
1
Cov
0%
_build_config_namespace
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Sweet::Config;
2 use latest;
3 use Moose::Role;
4  
5 use Carp;
6 use UNIVERSAL::require;
7  
8 use namespace::autoclean;
9  
10 requires qw(file_config_classname);
11  
12 has config => (
13 default => sub {
14 my $self = shift;
15  
16 my @namespace = @{ $self->_config_namespace };
17  
18 my $file_config = $self->_file_config;
19  
20 my $config = $file_config->content;
21  
22 for (my $i = 0 ; $i < scalar(@namespace) ; $i++) {
23 my $node = $namespace[$i];
24  
25 $config = $config->{$node};
26  
27 defined $config
28 or croak "Could not found configuration entry in $file_config: " . join(' > ', @namespace[ 0 .. $i ]) . "\n";
29 }
30  
31  
32 return $config;
33 },
34 is => 'ro',
35 isa => 'HashRef',
36 lazy => 1,
37 );
38  
39 has _file_config => (
40 default => sub {
41 my $self = shift;
42  
43 my $file_config_classname = $self->file_config_classname;
44 $file_config_classname->require;
45  
46 my $file_config = $file_config_classname->new;
47  
48 return $file_config;
49 },
50 is => 'ro',
51 isa => 'Sweet::File::Config',
52 lazy => 1,
53 );
54  
55 has _config_namespace => (
56 builder => '_build_config_namespace',
57 is => 'ro',
58 isa => 'ArrayRef[Str]',
59 lazy => 1,
60 );
61  
62 sub _build_config_namespace {
63 my $self = shift;
64  
65 my $package_name = $self->meta->name;
66  
67 my @namespace = split '::', $package_name;
68  
69 return \@namespace;
70 }
71  
72 1;
73  
74 __END__