line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Apachish::Reader; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2015-12-11'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.01'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
704
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
706
|
use parent qw(Config::Apachish::Base); |
|
1
|
|
|
|
|
297
|
|
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub _init_read { |
13
|
17
|
|
|
17
|
|
27
|
my $self = shift; |
14
|
|
|
|
|
|
|
|
15
|
17
|
|
|
|
|
70
|
$self->SUPER::_init_read; |
16
|
17
|
|
|
|
|
82
|
$self->{_context_stack} = [ ['', []] ]; # name, nodes |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _read_string { |
20
|
17
|
|
|
17
|
|
29
|
my ($self, $str) = @_; |
21
|
|
|
|
|
|
|
|
22
|
17
|
|
|
|
|
33
|
my $ctxs = $self->{_context_stack}; |
23
|
17
|
|
|
|
|
28
|
my $nodes = $ctxs->[0][1]; |
24
|
|
|
|
|
|
|
|
25
|
17
|
|
|
|
|
74
|
my @lines = split /^/, $str; |
26
|
17
|
|
|
|
|
57
|
local $self->{_linum} = 0; |
27
|
|
|
|
|
|
|
LINE: |
28
|
17
|
|
|
|
|
58
|
for my $line (@lines) { |
29
|
110
|
|
|
|
|
200
|
$self->{_linum}++; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#use DD; dd $ctxs; say ''; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# blank line |
34
|
110
|
100
|
|
|
|
355
|
if ($line !~ /\S/) { |
35
|
14
|
|
|
|
|
21
|
next LINE; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# open/close context line |
39
|
96
|
100
|
|
|
|
339
|
if ($line =~ s!\A\s*
|
40
|
44
|
100
|
|
|
|
145
|
if ($line =~ s!\A/!!) { |
41
|
|
|
|
|
|
|
# close context |
42
|
20
|
100
|
|
|
|
70
|
$self->_err("Invalid close context line") |
43
|
|
|
|
|
|
|
unless $line =~ /\A(\w+)>$/; |
44
|
19
|
|
|
|
|
39
|
my $ctx_name = lc($1); |
45
|
19
|
100
|
100
|
|
|
112
|
$self->_err("Close context line '$ctx_name' without ". |
46
|
|
|
|
|
|
|
"previous open") |
47
|
|
|
|
|
|
|
unless @$ctxs > 1 && $ctxs->[-1][0] eq $ctx_name; |
48
|
17
|
|
|
|
|
27
|
pop @$ctxs; |
49
|
|
|
|
|
|
|
} else { |
50
|
|
|
|
|
|
|
# open context |
51
|
24
|
100
|
|
|
|
125
|
$self->_err("Invalid open context line") |
52
|
|
|
|
|
|
|
unless $line =~ s/\A(\w+)(?:\s+(\S.*))?>$//; |
53
|
20
|
|
|
|
|
59
|
my $ctx_name = lc($1); |
54
|
20
|
|
|
|
|
33
|
my $args_s = $2; |
55
|
20
|
|
|
|
|
23
|
my $args; |
56
|
20
|
100
|
|
|
|
39
|
if (length($args_s)) { |
57
|
10
|
|
|
|
|
34
|
$args = $self->_parse_command_line($args_s); |
58
|
10
|
100
|
|
|
|
56
|
$self->_err("Invalid argument syntax in open context line") |
59
|
|
|
|
|
|
|
unless defined $args; |
60
|
|
|
|
|
|
|
} else { |
61
|
10
|
|
|
|
|
18
|
$args = []; |
62
|
|
|
|
|
|
|
} |
63
|
19
|
|
|
|
|
31
|
my $children = []; |
64
|
19
|
|
|
|
|
48
|
my $node = ['C', $ctx_name, $args, $children]; |
65
|
19
|
|
|
|
|
30
|
push @$nodes, $node; |
66
|
19
|
|
|
|
|
26
|
$nodes = $children; |
67
|
19
|
|
|
|
|
45
|
push @$ctxs, [$ctx_name, $nodes]; |
68
|
|
|
|
|
|
|
} |
69
|
36
|
|
|
|
|
89
|
next LINE; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# comment line |
73
|
52
|
100
|
|
|
|
139
|
if ($line =~ /\A\s*#/) { |
74
|
12
|
|
|
|
|
23
|
next LINE; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# directive line |
78
|
40
|
100
|
|
|
|
176
|
if ($line =~ /\A\s*(\w+)\s+(\S.*)$/) { |
79
|
38
|
|
|
|
|
89
|
my $dir_name = lc($1); |
80
|
38
|
|
|
|
|
124
|
my $args = $self->_parse_command_line($2); |
81
|
38
|
100
|
|
|
|
87
|
if (!defined($args)) { |
82
|
1
|
|
|
|
|
4
|
$self->_err("Invalid argument syntax in directive line"); |
83
|
|
|
|
|
|
|
} |
84
|
37
|
|
|
|
|
47
|
push @{$ctxs->[-1][1]}, ['D', $dir_name, $args]; |
|
37
|
|
|
|
|
119
|
|
85
|
|
|
|
|
|
|
# TODO: handle include |
86
|
37
|
|
|
|
|
78
|
next LINE; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
8
|
$self->_err("Invalid directive syntax"); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#use DD; dd $ctxs; |
93
|
|
|
|
|
|
|
|
94
|
6
|
50
|
|
|
|
19
|
if (@$ctxs > 1) { |
95
|
0
|
|
|
|
|
0
|
$self->_err("Unclosed context '$ctxs->[-1][0]'"); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
6
|
|
|
|
|
38
|
$ctxs->[0][1]; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
# ABSTRACT: Read Apachish configuration files |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |