line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FleetConf::Conf; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
91
|
use strict; |
|
15
|
|
|
|
|
30
|
|
|
15
|
|
|
|
|
846
|
|
4
|
15
|
|
|
15
|
|
80
|
use warnings; |
|
15
|
|
|
|
|
24
|
|
|
15
|
|
|
|
|
601
|
|
5
|
|
|
|
|
|
|
|
6
|
15
|
|
|
15
|
|
51722
|
use Parse::RecDescent; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
FleetConf::Conf - Simple configuration file format |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
array_value [ |
17
|
|
|
|
|
|
|
foo |
18
|
|
|
|
|
|
|
bar |
19
|
|
|
|
|
|
|
baz |
20
|
|
|
|
|
|
|
quux |
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
nested: 1 |
23
|
|
|
|
|
|
|
hash: 2 |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
[ |
26
|
|
|
|
|
|
|
nested |
27
|
|
|
|
|
|
|
array |
28
|
|
|
|
|
|
|
] |
29
|
|
|
|
|
|
|
] |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
hash_value { |
32
|
|
|
|
|
|
|
foo: first |
33
|
|
|
|
|
|
|
bar: second |
34
|
|
|
|
|
|
|
baz: third |
35
|
|
|
|
|
|
|
qux: fourth |
36
|
|
|
|
|
|
|
nested_hash { |
37
|
|
|
|
|
|
|
a: 1 |
38
|
|
|
|
|
|
|
b: 2 |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
nested_array [ |
41
|
|
|
|
|
|
|
alpha |
42
|
|
|
|
|
|
|
beta |
43
|
|
|
|
|
|
|
] |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
scalar_value = This is an example setting. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This is a very simple configuration file parser. I've invented a custom format because it was convenient for these needs and removed one more dependency. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $grammar = <<'EOGRAMMAR'; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
FleetConf_configuration: |
57
|
|
|
|
|
|
|
entries EOF |
58
|
|
|
|
|
|
|
{ $return = $item{entries} } |
59
|
|
|
|
|
|
|
| |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
entries: |
62
|
|
|
|
|
|
|
entry(s) |
63
|
|
|
|
|
|
|
{ $return = +{ map { ($_->[0] => $_->[1]) } grep { $_ } @{ $item{'entry(s)'} } }; } |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
entry: |
66
|
|
|
|
|
|
|
array |
67
|
|
|
|
|
|
|
| hash |
68
|
|
|
|
|
|
|
| scalar |
69
|
|
|
|
|
|
|
| comment |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
array: |
72
|
|
|
|
|
|
|
NAME ('=')(?) '[' array_entries ']' |
73
|
|
|
|
|
|
|
{ $return = [ $item{NAME} => $item{array_entries} ] } |
74
|
|
|
|
|
|
|
| |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
hash: |
77
|
|
|
|
|
|
|
NAME ('=')(?) '{' entries '}' |
78
|
|
|
|
|
|
|
{ $return = [ $item{NAME} => $item{entries} ] } |
79
|
|
|
|
|
|
|
| |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
array_entries: |
82
|
|
|
|
|
|
|
array_entry(s) |
83
|
|
|
|
|
|
|
{ $return = [ grep { $_ } @{ $item{'array_entry(s)'} } ]; } |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
array_entry: |
86
|
|
|
|
|
|
|
VALUE |
87
|
|
|
|
|
|
|
| '[' array_entries ']' |
88
|
|
|
|
|
|
|
{ $return = $item{array_entries} } |
89
|
|
|
|
|
|
|
| '{' entries '}' |
90
|
|
|
|
|
|
|
{ $return = $item{entries} } |
91
|
|
|
|
|
|
|
| comment |
92
|
|
|
|
|
|
|
| |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
scalar: |
95
|
|
|
|
|
|
|
NAME '=' VALUE |
96
|
|
|
|
|
|
|
{ $return = [ $item{NAME} => $item{VALUE} ] } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
comment: |
99
|
|
|
|
|
|
|
/#[^\n\r]*/ |
100
|
|
|
|
|
|
|
{ $return = ''; 1 } |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
NAME: |
103
|
|
|
|
|
|
|
/\w+/ |
104
|
|
|
|
|
|
|
| QUOTED_STRING |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
VALUE: |
107
|
|
|
|
|
|
|
QUOTED_STRING |
108
|
|
|
|
|
|
|
| /[^\]\}\n\r]*/ |
109
|
|
|
|
|
|
|
{ $item[1] =~ s/^\s+//; |
110
|
|
|
|
|
|
|
$item[1] =~ s/\s+$//; |
111
|
|
|
|
|
|
|
$return = $item[1]; 1 } |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
QUOTED_STRING: |
114
|
|
|
|
|
|
|
/"([^\\"]*(?:\\.[^\\"]*)*)"/ |
115
|
|
|
|
|
|
|
{ $return = $1; |
116
|
|
|
|
|
|
|
$return =~ s/\\(.)/$1/; 1 } |
117
|
|
|
|
|
|
|
| /'([^\\']*(?:\\.[^\\']*)*)'/ |
118
|
|
|
|
|
|
|
{ $return = $1; |
119
|
|
|
|
|
|
|
$return =~ s/\\(.)/$1/; 1 } |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
EOF: |
122
|
|
|
|
|
|
|
/\Z/ |
123
|
|
|
|
|
|
|
EOGRAMMAR |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $parser = Parse::RecDescent->new($grammar); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub new { |
128
|
|
|
|
|
|
|
my $class = shift; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $self = bless { |
131
|
|
|
|
|
|
|
conf => {}, |
132
|
|
|
|
|
|
|
}, $class; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub configuration { |
136
|
|
|
|
|
|
|
return shift->{conf}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub parse_file { |
140
|
|
|
|
|
|
|
my $self = shift; |
141
|
|
|
|
|
|
|
my $file = shift; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
open CF, $file or die "Cannot open configuration file $file: $!"; |
144
|
|
|
|
|
|
|
my $data = join '', ; |
145
|
|
|
|
|
|
|
close CF; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
return $self->parse_string($data); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub parse_string { |
151
|
|
|
|
|
|
|
my $self = shift; |
152
|
|
|
|
|
|
|
my $data = shift; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my $conf = $parser->FleetConf_configuration($data); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
die "Failed to build configuration." unless $conf; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
$self->{conf} = { |
159
|
|
|
|
|
|
|
%{ $self->{conf} }, |
160
|
|
|
|
|
|
|
%{ $conf }, |
161
|
|
|
|
|
|
|
}; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
return $self->{conf}; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AUTHOR |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp, Ehanenkamp@users.sourceforge.netE |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Copyright 2005 Andrew Sterling Hanenkamp. All Rights Reserved. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
FleetConf is licensed and distributed under the same terms as Perl itself. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1 |