line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Configuration::Trait::Attribute::ConfigKey; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
700
|
$MooseX::Configuration::Trait::Attribute::ConfigKey::VERSION = '0.02'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
7
|
use Moose::Role; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5229
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
94
|
use MooseX::Types::Moose qw( Str ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
14
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has config_section => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => Str, |
15
|
|
|
|
|
|
|
default => q{_}, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has config_key => ( |
19
|
|
|
|
|
|
|
is => 'ro', |
20
|
|
|
|
|
|
|
isa => Str, |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has original_default => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
isa => Str, |
27
|
|
|
|
|
|
|
predicate => 'has_original_default', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
around _process_options => sub { |
31
|
|
|
|
|
|
|
my $orig = shift; |
32
|
|
|
|
|
|
|
my ( $class, $name, $options ) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$class->throw_error( |
35
|
|
|
|
|
|
|
'Cannot define a configuration attribute unless you specify a config key name', |
36
|
|
|
|
|
|
|
data => $options |
37
|
|
|
|
|
|
|
) unless defined $options->{key} && length $options->{key}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$class->$orig( $name, $options ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$class->_process_default_or_builder_option($options); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$options->{config_section} = delete $options->{section} |
44
|
|
|
|
|
|
|
if exists $options->{section}; |
45
|
|
|
|
|
|
|
$options->{config_key} = delete $options->{key}; |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _process_default_or_builder_option { |
49
|
4
|
|
|
4
|
|
10
|
my $class = shift; |
50
|
4
|
|
|
|
|
8
|
my $options = shift; |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
11
|
$options->{lazy} = 1; |
53
|
|
|
|
|
|
|
|
54
|
4
|
100
|
|
|
|
28
|
my $section = defined $options->{section} ? $options->{section} : q{_}; |
55
|
4
|
|
|
|
|
10
|
my $key = $options->{key}; |
56
|
|
|
|
|
|
|
|
57
|
4
|
100
|
|
|
|
16
|
if ( exists $options->{default} ) { |
|
|
50
|
|
|
|
|
|
58
|
2
|
|
|
|
|
6
|
my $def = $options->{default}; |
59
|
|
|
|
|
|
|
|
60
|
2
|
50
|
|
|
|
6
|
if ( ref $options->{default} ) { |
61
|
|
|
|
|
|
|
$options->{default} = sub { |
62
|
0
|
|
|
0
|
|
0
|
my $val = $_[0]->_from_config( $section, $key ); |
63
|
0
|
0
|
|
|
|
0
|
return $val if defined $val; |
64
|
0
|
|
|
|
|
0
|
return $def->( $_[0] ); |
65
|
0
|
|
|
|
|
0
|
}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
|
|
|
|
|
|
$options->{default} = sub { |
69
|
1
|
|
|
1
|
|
696
|
my $val = $_[0]->_from_config( $section, $key ); |
70
|
1
|
50
|
|
|
|
15
|
return $val if defined $val; |
71
|
0
|
|
|
|
|
0
|
return $def; |
72
|
2
|
|
|
|
|
12
|
}; |
73
|
2
|
|
|
|
|
6
|
$options->{original_default} = $def; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
elsif ( $options->{builder} ) { |
77
|
0
|
|
|
|
|
0
|
my $builder = delete $options->{builder}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$options->{default} = sub { |
80
|
0
|
|
|
0
|
|
0
|
my $val = $_[0]->_from_config( $section, $key ); |
81
|
0
|
0
|
|
|
|
0
|
return $val if defined $val; |
82
|
0
|
|
|
|
|
0
|
return $_[0]->$builder(); |
83
|
0
|
|
|
|
|
0
|
}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
|
|
|
|
|
|
$options->{default} = sub { |
87
|
2
|
|
|
2
|
|
14634
|
return $_[0]->_from_config( $section, $key ); |
88
|
2
|
|
|
|
|
11
|
}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |