File Coverage

blib/lib/Dancer2/Core/Role/ConfigReader.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 40 40 100.0


line stmt bran cond sub pod time code
1             # ABSTRACT: Config reader role for Dancer2 core objects
2             package Dancer2::Core::Role::ConfigReader;
3             $Dancer2::Core::Role::ConfigReader::VERSION = '2.0.1';
4 147     147   561239 use Moo::Role;
  147         20069  
  147         2027  
5              
6 147     147   96457 use File::Spec;
  147         425  
  147         5006  
7 147     147   3486 use Config::Any;
  147         12704  
  147         4586  
8 147     147   1458 use Hash::Merge::Simple;
  147         3955  
  147         8812  
9 147     147   1014 use Carp 'croak';
  147         376  
  147         9875  
10 147     147   1095 use Module::Runtime 'require_module';
  147         384  
  147         1443  
11              
12 147     147   10075 use Dancer2::Core::Factory;
  147         405  
  147         4687  
13 147     147   925 use Dancer2::Core;
  147         398  
  147         4401  
14 147     147   1371 use Dancer2::Core::Types;
  147         342  
  147         1390  
15 147     147   2330701 use Dancer2::FileUtils 'path';
  147         482  
  147         46709  
16              
17             has config_location => (
18             is => 'ro',
19             isa => ReadableFilePath,
20             lazy => 1,
21             default => sub { $ENV{DANCER_CONFDIR} || $_[0]->location },
22             );
23              
24             # The type for this attribute is Str because we don't require
25             # an existing directory with configuration files for the
26             # environments. An application without environments is still
27             # valid and works.
28             has environments_location => (
29             is => 'ro',
30             isa => Str,
31             lazy => 1,
32             default => sub {
33             $ENV{DANCER_ENVDIR}
34             || File::Spec->catdir( $_[0]->config_location, 'environments' )
35             || File::Spec->catdir( $_[0]->location, 'environments' );
36             },
37             );
38              
39             # It is required to get environment from the caller.
40             # Environment should be passed down from Dancer2::Core::App.
41             has environment => (
42             is => 'ro',
43             isa => Str,
44             required => 1,
45             );
46              
47             # It is required to get location from the caller.
48             has location => (
49             is => 'ro',
50             isa => ReadableFilePath,
51             required => 1,
52             );
53              
54             1;
55              
56             __END__