File: PerlSections.pm

package info (click to toggle)
libapache-mod-perl 1.16-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,580 kB
  • ctags: 1,064
  • sloc: ansic: 4,489; perl: 4,415; sh: 305; makefile: 137
file content (173 lines) | stat: -rw-r--r-- 3,038 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package Apache::PerlSections;

use strict;
$Apache::PerlSections::VERSION = (qw$Revision: 1.6 $)[1];

use Devel::Symdump ();
use Data::Dumper ();

sub store {
    require IO::File;

    my($self, $file) = @_;
    my $fh = IO::File->new(">$file") or die "can't open $file $!\n";
    
    $fh->print($self->dump);
    
    $fh->close;
}

sub dump {
    my @retval = "package Apache::ReadConfig;";

    local $Data::Dumper::Indent = 1;

    my $stab = Devel::Symdump->rnew('Apache::ReadConfig');

    my %dump = (
	hashes  => 'HASH',
	scalars => 'SCALAR',
	arrays  => 'ARRAY',
    );

    while(my($meth,$type) = each %dump) {
	no strict 'refs';
	push @retval, "#$meth:\n";
	for my $name ($stab->$meth()) {
            my $s = Data::Dumper->Dump([*$name{$type}], ['*'.$name]);
	    $s =~ s/Apache:{0,2}ReadConfig:://;
            if($s =~ /^\$/) {
               $s =~ s/= \\/= /; #whack backwack
            }
	    push @retval, $s unless $s =~ /= (undef|\(\));$/;
	}
    }

    return join "\n", @retval, "1;", "__END__", "";
}

1;

__END__

=head1 NAME

Apache::PerlSections - Utilities for work with <Perl> sections

=head1 SYNOPSIS

    use Apache::PerlSections ();

=head1 DESCRIPTION

It is possible to configure you server entirely in Perl using
<Perl> sections in I<httpd.conf>.  This module is here to help
you with such a task.

=head1 METHODS

=over 4

=item dump

This method will dump out all the configuration variables mod_perl
will be feeding the the apache config gears.  The output is suitable
to read back in via C<eval>.

Example:

 <Perl>

 use Apache::PerlSections ();

 $Port = 8529;

 $Location{"/perl"} = {
     SetHandler => "perl-script",
     PerlHandler => "Apache::Registry",
     Options => "ExecCGI",
 };

 @DocumentIndex = qw(index.htm index.html);

 $VirtualHost{"www.foo.com"} = {
     DocumentRoot => "/tmp/docs",
     ErrorLog => "/dev/null",
     Location => {
	 "/" => {
	     Allowoverride => 'All',
	     Order => 'deny,allow',
	     Deny  => 'from all',
	     Allow => 'from foo.com',
	 }, 
     },
 };   

 print Apache::PerlSections->dump;

 </Perl>

This will print something like so:

 package Apache::ReadConfig;
 #scalars:

 $Port = 8529;

 #arrays:

 @DocumentIndex = (
   'index.htm',
   'index.html'
 );

 #hashes:

 %Location = (
   '/perl' => {
     PerlHandler => 'Apache::Registry',
     SetHandler => 'perl-script',
     Options => 'ExecCGI'
   }
 );

 %VirtualHost = (
   'www.foo.com' => {
     Location => {
       '/' => {
         Deny => 'from all',
         Order => 'deny,allow',
         Allow => 'from foo.com',
         Allowoverride => 'All'
       }
     },
     DocumentRoot => '/tmp/docs',
     ErrorLog => '/dev/null'
   }
 );

 1;
 __END__

=item store

This method will call the C<dump> method, writing the output
to a file, suitable to be pulled in via C<require>.

Example:

   Apache::PerlSections->store("httpd_config.pl");

   require 'httpd_config.pl';

=back

=head1 SEE ALSO

mod_perl(1), Data::Dumper(3), Devel::Symdump(3)

=head1 AUTHOR

Doug MacEachern