| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Spoon::Config; |
|
2
|
4
|
|
|
4
|
|
1588
|
use Spoon::Base -Base; |
|
|
4
|
|
|
|
|
8
|
|
|
|
4
|
|
|
|
|
39
|
|
|
3
|
4
|
|
|
4
|
|
4526
|
|
|
|
4
|
|
|
4
|
|
9
|
|
|
|
4
|
|
|
|
|
140
|
|
|
|
4
|
|
|
|
|
24
|
|
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
4067
|
|
|
4
|
|
|
|
|
|
|
const class_id => 'config'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
0
|
632
|
sub all { |
|
7
|
3
|
|
|
|
|
45
|
return %$self; |
|
8
|
|
|
|
|
|
|
} |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
0
|
3
|
sub default_configs { return } |
|
|
1
|
|
|
|
|
2
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new() { |
|
13
|
5
|
|
|
5
|
0
|
12
|
my $class = shift; |
|
14
|
5
|
|
|
|
|
16
|
my $self = bless {}, $class; |
|
15
|
4
|
50
|
|
|
|
26
|
my (@configs) = map { |
|
16
|
5
|
100
|
|
|
|
29
|
/\*/ ? (sort glob) : ($_) |
|
17
|
|
|
|
|
|
|
} @_ ? @_ : $self->default_configs; |
|
18
|
5
|
|
|
|
|
19
|
$self->add_config($self->default_config, 1); |
|
19
|
5
|
|
|
|
|
26
|
for my $config (@configs) { |
|
20
|
4
|
|
|
|
|
10
|
$self->rebless($self->add_config($config)); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
5
|
|
|
|
|
36
|
$self->init; |
|
23
|
5
|
|
|
|
|
16
|
return $self; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
0
|
0
|
sub add_field { |
|
27
|
0
|
|
|
|
|
0
|
my ($field, $default) = @_; |
|
28
|
0
|
|
|
|
|
0
|
field $field => $default; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
9
|
|
|
9
|
0
|
14
|
sub add_config { |
|
32
|
9
|
|
|
|
|
13
|
my $config = shift; |
|
33
|
9
|
50
|
|
|
|
24
|
my $hash = ref $config |
|
34
|
|
|
|
|
|
|
? $config |
|
35
|
|
|
|
|
|
|
: $self->hash_from_file($config); |
|
36
|
9
|
|
|
|
|
32
|
for my $key (keys %$hash) { |
|
37
|
54
|
|
|
|
|
142
|
field $key; |
|
38
|
54
|
|
|
|
|
10864
|
$self->{$key} = $hash->{$key}; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
9
|
|
|
|
|
30
|
return $hash; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
4
|
|
|
4
|
0
|
9
|
sub rebless { |
|
44
|
4
|
|
|
|
|
8
|
my $hash = shift; |
|
45
|
4
|
50
|
|
|
|
22
|
if (defined (my $config_class = $hash->{config_class})) { |
|
46
|
0
|
0
|
|
|
|
0
|
eval qq{ require $config_class }; die $@ if $@; |
|
|
0
|
|
|
|
|
0
|
|
|
47
|
0
|
|
|
|
|
0
|
bless $self, $config_class; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
0
|
0
|
0
|
sub hash_from_file { |
|
52
|
0
|
|
|
|
|
0
|
my $config = shift; |
|
53
|
0
|
0
|
|
|
|
0
|
die "Invalid name for config file '$config'\n" |
|
54
|
|
|
|
|
|
|
unless $config =~ /\.(\w+)$/; |
|
55
|
0
|
|
|
|
|
0
|
my $extension = lc("$1"); # quotes fix 5.8.0 perl bug |
|
56
|
0
|
|
|
|
|
0
|
my $method = "parse_${extension}_file"; |
|
57
|
0
|
0
|
|
|
|
0
|
-f $config ? $self->$method($config) : {}; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
0
|
0
|
sub parse_file { |
|
61
|
0
|
|
|
|
|
0
|
$self->parse_yaml_file(@_); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
0
|
0
|
sub parse_yaml_file { |
|
65
|
0
|
|
|
|
|
0
|
my $file = shift; |
|
66
|
0
|
|
|
|
|
0
|
$self->parse_yaml(io($file)->utf8->all); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
0
|
0
|
sub parse_yaml { |
|
70
|
0
|
|
|
|
|
0
|
my $yaml = shift; |
|
71
|
0
|
|
|
|
|
0
|
my $hash = {}; |
|
72
|
0
|
|
|
|
|
0
|
my $latest_key = ''; |
|
73
|
0
|
|
|
|
|
0
|
for (split /\n/, $yaml) { |
|
74
|
0
|
0
|
|
|
|
0
|
next if (/^#/); |
|
75
|
0
|
0
|
0
|
|
|
0
|
if (/^-\s*(.*)$/) { |
|
|
|
0
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
$hash->{$latest_key} = [] unless ref $hash->{$latest_key}; |
|
77
|
0
|
|
|
|
|
0
|
push @{$hash->{$latest_key}}, $1; |
|
|
0
|
|
|
|
|
0
|
|
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
elsif (/(.*?)\s*:\s+(.*?)\s*$/ or /(.*?):()\s*$/) { |
|
80
|
0
|
|
|
|
|
0
|
$hash->{$1} = $2; |
|
81
|
0
|
|
|
|
|
0
|
$latest_key = $1; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
0
|
|
|
|
|
0
|
return $hash; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
5
|
|
|
5
|
0
|
8
|
sub default_config { |
|
88
|
|
|
|
|
|
|
+{ |
|
89
|
5
|
|
|
|
|
14
|
$self->default_classes, |
|
90
|
|
|
|
|
|
|
plugin_classes => [$self->default_plugin_classes], |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
5
|
|
|
5
|
0
|
7
|
sub default_classes { |
|
95
|
|
|
|
|
|
|
( |
|
96
|
5
|
|
|
|
|
34
|
cgi_class => 'Spoon::CGI', |
|
97
|
|
|
|
|
|
|
config_class => 'Spoon::Config', |
|
98
|
|
|
|
|
|
|
formatter_class => 'Spoon::Formatter', |
|
99
|
|
|
|
|
|
|
headers_class => 'Spoon::Headers', |
|
100
|
|
|
|
|
|
|
hooks_class => 'Spoon::Hooks', |
|
101
|
|
|
|
|
|
|
hub_class => 'Spoon::Hub', |
|
102
|
|
|
|
|
|
|
main_class => 'Spoon', |
|
103
|
|
|
|
|
|
|
registry_class => 'Spoon::Registry', |
|
104
|
|
|
|
|
|
|
template_class => 'Spoon::Template', |
|
105
|
|
|
|
|
|
|
) |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
5
|
|
|
5
|
0
|
8
|
sub default_plugin_classes { () } |
|
|
5
|
|
|
|
|
104
|
|
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |