⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perlsections.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
  $PerlConfig .= "Alias /foo /bar\n";See alsoC<L<$r-E<gt>add_config|docs::2.0::api::Apache2::RequestUtil/C_add_config_>>=head1 Configuration VariablesThere are a few variables that can be set to change the defaultbehaviour of C<E<lt>PerlE<gt>> sections.=head2 C<$Apache2::PerlSections::Save>Each C<E<lt>PerlE<gt>> section is evaluated in its unique namespace,by default residing in a sub-namespace of C<Apache2::ReadConfig::>,therefore any local variables will end up in that namespace. Forexample if a C<E<lt>PerlE<gt>> section happened to be in fileF</tmp/httpd.conf> starting on line 20, the namespace:C<Apache2::ReadConfig::tmp::httpd_conf::line_20> will be used. Now ifit had:  <Perl>    $foo     = 5;    my $bar  = 6;    $My::tar = 7;  </Perl>The local global variable C<$foo> becomesC<$Apache2::ReadConfig::tmp::httpd_conf::line_20::foo>, the othervariable remain where they are.By default, the namespace in which C<E<lt>PerlE<gt>> sections areevaluated is cleared after each block closes. In our example nukingC<$Apache2::ReadConfig::tmp::httpd_conf::line_20::foo>, leaving therest untouched.By setting C<$Apache2::PerlSections::Save> to a true value, the contentof those namespaces will be preserved and will be available forinspection by C<L<Apache2::Status|docs::2.0::api::Apache2::Status>> andC<L<Apache2::PerlSections-E<gt>dump|/C_Apache2__PerlSections_E_gt_dump_>>In our example C<$Apache2::ReadConfig::tmp::httpd_conf::line_20::foo>will still be accessible from other perl code, after theC<E<lt>PerlE<gt>> section was parsed.=head1 PerlSections Dumping=head2 C<Apache2::PerlSections-E<gt>dump>This method will dump out all the configuration variables mod_perlwill be feeding to the apache config gears. The output is suitable toread back in via C<eval>.  my $dump = Apache2::PerlSections->dump;=over 4=item ret: C<$dump> ( string / C<undef> )A string dump of all the Perl code encountered in E<lt>PerlE<gt> blocks,suitable to be read back via C<eval>=backFor example:  <Perl>    $Apache2::PerlSections::Save = 1;    $Listen = 8529;    $Location{"/perl"} = {     SetHandler => "perl-script",     PerlHandler => "ModPerl::Registry",     Options => "ExecCGI",  };    @DirectoryIndex = 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',       },     },  };  </Perl>    <Perl>  print Apache2::PerlSections->dump;  </Perl>This will print something like this:  $Listen = 8529;    @DirectoryIndex = (    'index.htm',    'index.html'  );    $Location{'/perl'} = (      PerlHandler => 'Apache2::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__It is important to put the call to C<dump> in it's own C<E<lt>PerlE<gt>>section, otherwise the content of the current C<E<lt>PerlE<gt>> sectionwill not be dumped.=head2 C<Apache2::PerlSections-E<gt>store>This method will call the C<dump> method, writing the outputto a file, suitable to be pulled in via C<require> or C<do>.  Apache2::PerlSections->store($filename);=over 4=item arg1: C<$filename> (string)The filename to save the dump output to=item ret: no return value=back=head1 Advanced APImod_perl 2.0 now introduces the same general concept of handlers toC<E<lt>PerlE<gt>> sections.  Apache2::PerlSections simply being thedefault handler for them.To specify a different handler for a given perl section, an extrahandler argument must be given to the section:  <Perl handler="My::PerlSection::Handler" somearg="test1">    $foo = 1;    $bar = 2;  </Perl>And in My/PerlSection/Handler.pm:  sub My::Handler::handler : handler {      my ($self, $parms, $args) = @_;      #do your thing!  }So, when that given C<E<lt>PerlE<gt>> block in encountered, the codewithin will first be evaluated, then the handler routine will beinvoked with 3 arguments:=over=item arg1: C<$self>self-explanatory=item arg2: C<$parms>( C<L<Apache2::CmdParms|docs::2.0::api::Apache2::CmdParms>> )C<$parms> is specific for the current Container, for example, youmight want to call C<$parms-E<gt>server()> to get the current server.=item arg3: C<$args>( C<L<APR::Table object|docs::2.0::api::APR::Table>>)the table object of the section arguments. The 2 guaranteed ones willbe:  $args->{'handler'} = 'My::PerlSection::Handler';  $args->{'package'} = 'Apache2::ReadConfig';Other C<name="value"> pairs given on the C<E<lt>PerlE<gt>> line willalso be included.=backAt this point, it's up to the handler routing to inspect the namespaceof the C<$args>-E<gt>{'package'} and chooses what to do.The most likely thing to do is to feed configuration data back intoapache. To do that, use Apache2::Server-E<gt>add_config("directive"),for example:  $parms->server->add_config("Alias /foo /bar");Would create a new alias. The source code of C<Apache2::PerlSections>is a good place to look for a practical example.=head1 Verifying C<E<lt>PerlE<gt>> SectionsIf the C<E<lt>PerlE<gt>> sections include no code requiring a runningmod_perl, it is possible to check those from the command line. But thefollowing trick should be used:  # file: httpd.conf  <Perl>  #!perl    # ... code here ...    __END__  </Perl>Now you can run:  % perl -c httpd.conf=head1 Bugs=head2 E<lt>PerlE<gt> directive missing closing 'E<gt>'httpd-2.0.47 had a bug in the configuration parser which caused thestartup failure with the following error:  Starting httpd:  Syntax error on line ... of /etc/httpd/conf/httpd.conf:  <Perl> directive missing closing '>'     [FAILED]This has been fixed in httpd-2.0.48. If you can't upgrade to this or ahigher version, please add a space before the closing 'E<gt>' of theopening tag as a workaround. So if you had:  <Perl>  # some code  </Perl>change it to be:  <Perl >  # some code  </Perl>=head2 E<lt>PerlE<gt>[...]E<gt> was not closed.On encountering a one-line E<lt>PerlE<gt> block, httpd's configuration parser will cause a startupfailure with an error similar to this one:  Starting httpd:  Syntax error on line ... of /etc/httpd/conf/httpd.conf:  <Perl>use> was not closed.If you have written a simple one-line E<lt>PerlE<gt>section like this one :  <Perl>use Apache::DBI;</Perl>change it to be:   <Perl>   use Apache::DBI;   </Perl>This is caused by a limitation of httpd's configurationparser and is not likely to be changed to allow one-lineblock like the example above. Use multi-line blocks instead.=head1 See AlsoL<mod_perl 2.0 documentation|docs::2.0::index>.=head1 Copyrightmod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0.=head1 AuthorsL<The mod_perl development team and numerouscontributors|about::contributors::people>.=cut

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -