Apache-Config-Preproc
view release on metacpan or search on metacpan
lib/Apache/Config/Preproc.pm view on Meta::CPAN
=item B<ifdefine>
Expands the B<E<lt>IfDefineE<gt>> statements.
=item B<locus>
Attaches file location information to each node in the parse tree.
=item B<macro>
Expands the B<E<lt>MacroE<gt>> statements.
=back
See the section B<MODULES> for a detailed description of these modules.
More expansions can be easily implemented by supplying a corresponding
expansion module (see the section B<MODULE INTERNALS> below).
If the B<-expand> argument is not supplied, the following default is
used:
lib/Apache/Config/Preproc.pm view on Meta::CPAN
foreach ($x->select) {
print $_->locus
}
See L<Text::Locus> for a detailed discussion of the locus object and its
methods.
=head2 macro
Processes B<Macro> and B<Use> statements (see B<mod_macro>). B<Macro>
statements are removed. Each B<Use> statement is replaced by the expansion
of the macro named in its argument.
The constructor accepts the following arguments:
=over 4
=item B<keep =E<gt>> I<$listref>
List of macro names to exclude from expanding. Each B<E<lt>MacroE<gt>> and
B<Use> statement with a name from I<$listref> as its first argument will be
retained in the parse tree.
As a syntactic sugar, I<$listref> can also be a scalar value. This is
convenient when a single macro name is to be retained.
=back
=head1 MODULE INTERNALS
lib/Apache/Config/Preproc/macro.pm view on Meta::CPAN
=head1 SYNOPSIS
$x = new Apache::Config::Preproc '/path/to/httpd.conf',
-expand => [ qw(macro) ];
$x = new Apache::Config::Preproc '/path/to/httpd.conf',
-expand => [ { macro => [ keep => $listref ] } ];
=head1 DESCRIPTION
Processes B<Macro> and B<Use> statements (see B<mod_macro>) in the
Apache configuration parse tree.
B<Macro> statements are removed. Each B<Use> statement is replaced by the
expansion of the macro named in its argument.
The constructor accepts the following arguments:
=over 4
=item B<keep =E<gt>> I<$listref>
List of macro names to exclude from expanding. Each B<E<lt>MacroE<gt>> and
B<Use> statement with a name from I<$listref> as its first argument will be
retained in the parse tree.
As a syntactic sugar, I<$listref> can also be a scalar value. This is
convenient when a single macro name is to be retained.
=back
=head1 SEE ALSO
t/04macro00.t view on Meta::CPAN
plan test => 1;
use TestPreproc;
my $obj = new TestPreproc -expand => ['macro'];
ok($obj->dump_raw, $obj->dump_expect);
__DATA__
!>httpd.conf
ServerName localhost
<Macro vhost $name $port $dir>
<VirtualHost *:$port>
# Comment
ServerName $name
DocumentRoot $dir
<Directory $dir>
Require all granted
</Directory>
</VirtualHost>
</Macro>
Use vhost foo 80 /var/www/foo
Use vhost bar 443 /var/www/bar
Use vhost baz 80 /var/baz
!=
ServerName localhost
<VirtualHost *:80>
# Comment
ServerName foo
DocumentRoot /var/www/foo
t/04macro01.t view on Meta::CPAN
plan test => 1;
use TestPreproc;
my $obj = new TestPreproc -expand => ['macro'];
ok($obj->dump_raw, $obj->dump_expect);
__DATA__
!>httpd.conf
ServerName localhost
<Macro SSL $domain>
SSLEngine on
SSLCertificateFile /etc/ssl/acme/$domain.pem
</Macro>
<Macro vhost $name $port $dir>
<VirtualHost *:$port>
ServerName $name
DocumentRoot $dir
Use SSL $name
</VirtualHost>
</Macro>
Use vhost foo 80 /var/www/foo
!=
ServerName localhost
<VirtualHost *:80>
ServerName foo
DocumentRoot /var/www/foo
SSLEngine on
SSLCertificateFile /etc/ssl/acme/foo.pem
t/04macro02.t view on Meta::CPAN
use Test;
plan test => 1;
use TestPreproc;
my $obj = new TestPreproc -expand => [ { macro => [ keep => 'SSL' ] } ];
ok($obj->dump_raw, $obj->dump_expect);
__DATA__
!>httpd.conf
ServerName localhost
<Macro SSL $domain>
SSLEngine on
SSLCertificateFile /etc/ssl/acme/$domain.pem
</Macro>
<Macro vhost $name $port $dir>
<VirtualHost *:$port>
ServerName $name
DocumentRoot $dir
Use SSL $name
</VirtualHost>
</Macro>
Use vhost foo 80 /var/www/foo
!=
ServerName localhost
<Macro SSL $domain>
SSLEngine on
SSLCertificateFile /etc/ssl/acme/$domain.pem
</Macro>
<VirtualHost *:80>
ServerName foo
DocumentRoot /var/www/foo
Use SSL foo
</VirtualHost>
!$
t/06locus04.t view on Meta::CPAN
plan test => 1;
use TestPreproc;
my $obj = new TestPreproc -expand => [qw(locus macro)];
ok($obj->dump_reformat_synclines,$obj->dump_expect);
__DATA__
!>httpd.conf
# Start of file
ServerRoot "$server_root"
<Macro X $arg>
Foo $arg
</Macro>
EndStatement true
Use X bar
!=
# $server_root/httpd.conf:1
# Start of file
# $server_root/httpd.conf:2
ServerRoot "$server_root"
# $server_root/httpd.conf:6
EndStatement true
# $server_root/httpd.conf:4
t/99all00.t view on Meta::CPAN
Listen 8080
</IfDefine>
Timeout 300
!>conf.d/load.conf
# Load prefork mpm
LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so
# Load logging modules
LoadModule log_config_module lib/httpd/modules/mod_log_config.so
LoadModule logio_module lib/httpd/modules/mod_logio.so
!>conf.d/vhost.conf
<Macro vhost $name $port $dir>
<VirtualHost *:$port>
# Comment
ServerName $name
DocumentRoot $dir
<Directory $dir>
Require all granted
</Directory>
</VirtualHost>
</Macro>
!>def.conf
Define FOO
!>mpm.conf
<IfModule !mpm_netware_module>
PidFile "/var/run/httpd.pid"
</IfModule>
<IfModule mpm_prefork_module>
StartServers 1
MinSpareServers 1
MaxSpareServers 1
( run in 0.558 second using v1.01-cache-2.11-cpan-fd5d4e115d8 )