equal
deleted
inserted
replaced
1 package App::read_httpd_conf; |
|
2 |
|
3 use 5.010; |
|
4 use strict; |
|
5 use warnings; |
|
6 use Carp; |
|
7 use File::Basename; |
|
8 use Pod::Usage; |
|
9 |
|
10 our $VERSION = '0.1'; |
|
11 |
|
12 sub main { |
|
13 shift if $_[0] eq __PACKAGE__; |
|
14 return read_file(@_) ? 0 : 1; |
|
15 } |
|
16 |
|
17 sub read_file { |
|
18 my ($file, $basedir) = @_; |
|
19 $file =~ s{/+}{/}g; |
|
20 $basedir //= dirname $file; |
|
21 open(my $fh, '<', $file) |
|
22 or croak "Can't open $file: $!\n"; |
|
23 say "# 1 $file"; |
|
24 while (<$fh>) { |
|
25 if (s{\\$}{}) { |
|
26 chomp; |
|
27 $_ .= <$fh>; |
|
28 redo; |
|
29 } |
|
30 if (/^\s*include(?:optional)?\s+(?<quote>["'])?(?<file>.*?)\k<quote>?\s*$/i) { |
|
31 my $include_file = substr($+{file}, 0, 1) eq '/' ? $+{file} : "$basedir/$+{file}"; |
|
32 say "# $. $file INCLUDE $include_file"; |
|
33 read_file($_, $basedir) foreach (glob -d $include_file ? "$include_file/*" : $include_file); |
|
34 next; |
|
35 } |
|
36 |
|
37 print; |
|
38 } |
|
39 return 1; |
|
40 } |
|
41 |
|
42 1; |
|
43 |
|
44 __END__ |
|
45 |
|
46 =head1 NAME |
|
47 |
|
48 App::read_httpd_conf |
|
49 |
|
50 =head1 SYNOPSIS |
|
51 |
|
52 use App::read_httpd_conf; |
|
53 App::read_httpd_conf->main($file); |
|
54 |
|
55 =head1 DESCRIPTION |
|
56 |
|
57 This small package reads the apache config file and writes the parsed |
|
58 and included files to the standard file descriptor. If you want to proceess |
|
59 the output in your own script, do something like this: |
|
60 |
|
61 my $output; |
|
62 open(my $fh, '>', \$output); |
|
63 my $oldfh = select($fh); |
|
64 App::read_httpd_conf->read_file($config)); |
|
65 select($oldfh); |
|
66 |
|
67 =head1 AUTHOR |
|
68 |
|
69 Heiko Schlittermann L<hs@schlittermann.de> |
|
70 |
|
71 =cut |
|