| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# ABSTRACT: Role that represents the config of Dancer2 App |
|
2
|
|
|
|
|
|
|
package Dancer2::Core::Role::HasConfig; |
|
3
|
|
|
|
|
|
|
$Dancer2::Core::Role::HasConfig::VERSION = '2.1.0'; |
|
4
|
162
|
|
|
162
|
|
791685
|
use Moo::Role; |
|
|
162
|
|
|
|
|
13602
|
|
|
|
162
|
|
|
|
|
1464
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
162
|
|
|
162
|
|
93218
|
use Config::Any; |
|
|
162
|
|
|
|
|
24788
|
|
|
|
162
|
|
|
|
|
5891
|
|
|
7
|
162
|
|
|
162
|
|
2009
|
use Hash::Merge::Simple; |
|
|
162
|
|
|
|
|
1472
|
|
|
|
162
|
|
|
|
|
10370
|
|
|
8
|
162
|
|
|
162
|
|
1133
|
use Carp 'croak'; |
|
|
162
|
|
|
|
|
388
|
|
|
|
162
|
|
|
|
|
10942
|
|
|
9
|
162
|
|
|
162
|
|
1168
|
use Module::Runtime qw{ require_module use_module }; |
|
|
162
|
|
|
|
|
420
|
|
|
|
162
|
|
|
|
|
1695
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
162
|
|
|
162
|
|
13696
|
use Dancer2::Core::Factory; |
|
|
162
|
|
|
|
|
486
|
|
|
|
162
|
|
|
|
|
5076
|
|
|
12
|
162
|
|
|
162
|
|
923
|
use Dancer2::Core; |
|
|
162
|
|
|
|
|
433
|
|
|
|
162
|
|
|
|
|
4357
|
|
|
13
|
162
|
|
|
162
|
|
1952
|
use Dancer2::Core::Types; |
|
|
162
|
|
|
|
|
455
|
|
|
|
162
|
|
|
|
|
1543
|
|
|
14
|
162
|
|
|
162
|
|
2484946
|
use Dancer2::ConfigUtils 'normalize_config_entry'; |
|
|
162
|
|
|
|
|
468
|
|
|
|
162
|
|
|
|
|
40498
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has config => ( |
|
17
|
|
|
|
|
|
|
is => 'ro', |
|
18
|
|
|
|
|
|
|
isa => HashRef, |
|
19
|
|
|
|
|
|
|
lazy => 1, |
|
20
|
|
|
|
|
|
|
builder => '_build_config', |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has local_triggers => ( |
|
24
|
|
|
|
|
|
|
is => 'ro', |
|
25
|
|
|
|
|
|
|
isa => HashRef, |
|
26
|
|
|
|
|
|
|
default => sub { +{} }, |
|
27
|
|
|
|
|
|
|
); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has global_triggers => ( |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
isa => HashRef, |
|
32
|
|
|
|
|
|
|
default => sub { |
|
33
|
|
|
|
|
|
|
my $triggers = { |
|
34
|
|
|
|
|
|
|
traces => sub { |
|
35
|
|
|
|
|
|
|
my ( $self, $traces ) = @_; |
|
36
|
|
|
|
|
|
|
# Carp is already a dependency |
|
37
|
|
|
|
|
|
|
$Carp::Verbose = $traces ? 1 : 0; |
|
38
|
|
|
|
|
|
|
}, |
|
39
|
|
|
|
|
|
|
}; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $runner_config; |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
162
|
|
|
162
|
|
1392
|
no warnings 'once'; |
|
|
162
|
|
|
|
|
491
|
|
|
|
162
|
|
|
|
|
96075
|
|
|
44
|
|
|
|
|
|
|
$runner_config = defined $Dancer2::runner |
|
45
|
|
|
|
|
|
|
? Dancer2->runner->config |
|
46
|
|
|
|
|
|
|
: {}; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
for my $global ( keys %$runner_config ) { |
|
50
|
|
|
|
|
|
|
next if exists $triggers->{$global}; |
|
51
|
|
|
|
|
|
|
$triggers->{$global} = sub { |
|
52
|
|
|
|
|
|
|
my ($self, $value) = @_; |
|
53
|
|
|
|
|
|
|
Dancer2->runner->config->{$global} = $value; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return $triggers; |
|
58
|
|
|
|
|
|
|
}, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _set_config_entries { |
|
62
|
161
|
|
|
161
|
|
599
|
my ( $self, @args ) = @_; |
|
63
|
161
|
|
|
|
|
397
|
my $no = scalar @args; |
|
64
|
161
|
|
|
|
|
702
|
while (@args) { |
|
65
|
167
|
|
|
|
|
1028
|
$self->_set_config_entry( shift(@args), shift(@args) ); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
161
|
|
|
|
|
283006
|
return $no; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _set_config_entry { |
|
71
|
167
|
|
|
167
|
|
551
|
my ( $self, $name, $value ) = @_; |
|
72
|
|
|
|
|
|
|
|
|
73
|
167
|
|
|
|
|
1345
|
$value = normalize_config_entry( $name, $value ); |
|
74
|
167
|
|
|
|
|
5360
|
$value = $self->_compile_config_entry( $name, $value, $self->config ); |
|
75
|
167
|
|
|
|
|
5819
|
$self->config->{$name} = $value; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
3
|
|
|
3
|
1
|
2123
|
sub settings { shift->config } |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub setting { |
|
81
|
539
|
|
|
539
|
1
|
8417
|
my $self = shift; |
|
82
|
539
|
|
|
|
|
1997
|
my @args = @_; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return ( scalar @args == 1 ) |
|
85
|
539
|
100
|
|
|
|
4068
|
? $self->settings->{ $args[0] } |
|
86
|
|
|
|
|
|
|
: $self->_set_config_entries(@args); |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub has_setting { |
|
90
|
4
|
|
|
4
|
1
|
5863
|
my ( $self, $name ) = @_; |
|
91
|
4
|
|
|
|
|
144
|
return exists $self->config->{$name}; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# private |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _compile_config_entry { |
|
97
|
167
|
|
|
167
|
|
2823
|
my ( $self, $name, $value, $config ) = @_; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $trigger = exists $self->local_triggers->{$name} ? |
|
100
|
|
|
|
|
|
|
$self->local_triggers->{$name} : |
|
101
|
167
|
100
|
|
|
|
1617
|
$self->global_triggers->{$name}; |
|
102
|
|
|
|
|
|
|
|
|
103
|
167
|
100
|
|
|
|
735
|
defined $trigger or return $value; |
|
104
|
|
|
|
|
|
|
|
|
105
|
101
|
|
|
|
|
582
|
return $trigger->( $self, $value, $config ); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |