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