| 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.0.1'; |
|
4
|
158
|
|
|
158
|
|
810255
|
use Moo::Role; |
|
|
158
|
|
|
|
|
13058
|
|
|
|
158
|
|
|
|
|
1542
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
158
|
|
|
158
|
|
92168
|
use File::Spec; |
|
|
158
|
|
|
|
|
420
|
|
|
|
158
|
|
|
|
|
5394
|
|
|
7
|
158
|
|
|
158
|
|
5580
|
use Config::Any; |
|
|
158
|
|
|
|
|
20713
|
|
|
|
158
|
|
|
|
|
5676
|
|
|
8
|
158
|
|
|
158
|
|
2692
|
use Hash::Merge::Simple; |
|
|
158
|
|
|
|
|
1337
|
|
|
|
158
|
|
|
|
|
11539
|
|
|
9
|
158
|
|
|
158
|
|
1273
|
use Carp 'croak'; |
|
|
158
|
|
|
|
|
384
|
|
|
|
158
|
|
|
|
|
11805
|
|
|
10
|
158
|
|
|
158
|
|
1220
|
use Module::Runtime qw{ require_module use_module }; |
|
|
158
|
|
|
|
|
379
|
|
|
|
158
|
|
|
|
|
1697
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
158
|
|
|
158
|
|
12885
|
use Dancer2::Core::Factory; |
|
|
158
|
|
|
|
|
444
|
|
|
|
158
|
|
|
|
|
4916
|
|
|
13
|
158
|
|
|
158
|
|
1006
|
use Dancer2::Core; |
|
|
158
|
|
|
|
|
382
|
|
|
|
158
|
|
|
|
|
5506
|
|
|
14
|
158
|
|
|
158
|
|
2006
|
use Dancer2::Core::Types; |
|
|
158
|
|
|
|
|
476
|
|
|
|
158
|
|
|
|
|
1737
|
|
|
15
|
158
|
|
|
158
|
|
2414370
|
use Dancer2::FileUtils 'path'; |
|
|
158
|
|
|
|
|
439
|
|
|
|
158
|
|
|
|
|
13887
|
|
|
16
|
158
|
|
|
158
|
|
2174
|
use Dancer2::ConfigUtils 'normalize_config_entry'; |
|
|
158
|
|
|
|
|
586
|
|
|
|
158
|
|
|
|
|
36115
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has config => ( |
|
19
|
|
|
|
|
|
|
is => 'ro', |
|
20
|
|
|
|
|
|
|
isa => HashRef, |
|
21
|
|
|
|
|
|
|
lazy => 0, |
|
22
|
|
|
|
|
|
|
builder => '_build_config', |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has local_triggers => ( |
|
26
|
|
|
|
|
|
|
is => 'ro', |
|
27
|
|
|
|
|
|
|
isa => HashRef, |
|
28
|
|
|
|
|
|
|
default => sub { +{} }, |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has global_triggers => ( |
|
32
|
|
|
|
|
|
|
is => 'ro', |
|
33
|
|
|
|
|
|
|
isa => HashRef, |
|
34
|
|
|
|
|
|
|
default => sub { |
|
35
|
|
|
|
|
|
|
my $triggers = { |
|
36
|
|
|
|
|
|
|
traces => sub { |
|
37
|
|
|
|
|
|
|
my ( $self, $traces ) = @_; |
|
38
|
|
|
|
|
|
|
# Carp is already a dependency |
|
39
|
|
|
|
|
|
|
$Carp::Verbose = $traces ? 1 : 0; |
|
40
|
|
|
|
|
|
|
}, |
|
41
|
|
|
|
|
|
|
}; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $runner_config; |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
158
|
|
|
158
|
|
1549
|
no warnings 'once'; |
|
|
158
|
|
|
|
|
670
|
|
|
|
158
|
|
|
|
|
91841
|
|
|
46
|
|
|
|
|
|
|
$runner_config = defined $Dancer2::runner |
|
47
|
|
|
|
|
|
|
? Dancer2->runner->config |
|
48
|
|
|
|
|
|
|
: {}; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
for my $global ( keys %$runner_config ) { |
|
52
|
|
|
|
|
|
|
next if exists $triggers->{$global}; |
|
53
|
|
|
|
|
|
|
$triggers->{$global} = sub { |
|
54
|
|
|
|
|
|
|
my ($self, $value) = @_; |
|
55
|
|
|
|
|
|
|
Dancer2->runner->config->{$global} = $value; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return $triggers; |
|
60
|
|
|
|
|
|
|
}, |
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _set_config_entries { |
|
64
|
158
|
|
|
158
|
|
889
|
my ( $self, @args ) = @_; |
|
65
|
158
|
|
|
|
|
409
|
my $no = scalar @args; |
|
66
|
158
|
|
|
|
|
709
|
while (@args) { |
|
67
|
164
|
|
|
|
|
848
|
$self->_set_config_entry( shift(@args), shift(@args) ); |
|
68
|
|
|
|
|
|
|
} |
|
69
|
158
|
|
|
|
|
295606
|
return $no; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _set_config_entry { |
|
73
|
164
|
|
|
164
|
|
516
|
my ( $self, $name, $value ) = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
164
|
|
|
|
|
998
|
$value = normalize_config_entry( $name, $value ); |
|
76
|
164
|
|
|
|
|
5042
|
$value = $self->_compile_config_entry( $name, $value, $self->config ); |
|
77
|
164
|
|
|
|
|
6959
|
$self->config->{$name} = $value; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
1
|
|
|
1
|
1
|
1917
|
sub settings { shift->config } |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub setting { |
|
83
|
528
|
|
|
528
|
1
|
1610
|
my $self = shift; |
|
84
|
528
|
|
|
|
|
2613
|
my @args = @_; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return ( scalar @args == 1 ) |
|
87
|
528
|
100
|
|
|
|
4332
|
? $self->settings->{ $args[0] } |
|
88
|
|
|
|
|
|
|
: $self->_set_config_entries(@args); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub has_setting { |
|
92
|
2
|
|
|
2
|
1
|
6
|
my ( $self, $name ) = @_; |
|
93
|
2
|
|
|
|
|
11
|
return exists $self->config->{$name}; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# private |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _compile_config_entry { |
|
99
|
164
|
|
|
164
|
|
2577
|
my ( $self, $name, $value, $config ) = @_; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $trigger = exists $self->local_triggers->{$name} ? |
|
102
|
|
|
|
|
|
|
$self->local_triggers->{$name} : |
|
103
|
164
|
100
|
|
|
|
1496
|
$self->global_triggers->{$name}; |
|
104
|
|
|
|
|
|
|
|
|
105
|
164
|
100
|
|
|
|
710
|
defined $trigger or return $value; |
|
106
|
|
|
|
|
|
|
|
|
107
|
97
|
|
|
|
|
542
|
return $trigger->( $self, $value, $config ); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |