相关文章推荐
机灵的香槟  ·  HBuilderX - ...·  1 年前    · 
独立的火龙果  ·  modbus ...·  1 年前    · 
  # make the constants available but don't import them
  use Apache2::Const -compile => qw(constant names ...);
  # w/o the => syntax sugar
  use Apache2::Const ("-compile", qw(constant names ...));
  # compile and import the constants
  use Apache2::Const qw(constant names ...);

This package contains constants specific to Apache features.

mod_perl 2.0 comes with several hundreds of constants, which you don't want to make available to your Perl code by default, due to CPU and memory overhead. Therefore when you want to use a certain constant you need to explicitly ask to make it available.

For example, the code:

  use Apache2::Const -compile => qw(FORBIDDEN OK);

makes the constants Apache2::Const::FORBIDDEN and Apache2::Const::OK available to your code, but they aren't imported. In which case you need to use a fully qualified constants, as in:

  return Apache2::Const::OK;

If you drop the argument -compile and write:

  use Apache2::Const qw(FORBIDDEN OK);

Then both constants are imported into your code's namespace and can be used standalone like so:

  return OK;

Both, due to the extra memory requirement, when importing symbols, and since there are constants in other namespaces (e.g., APR:: and ModPerl:: , and non-mod_perl modules) which may contain the same names, it's not recommended to import constants. I.e. you want to use the -compile construct.

Finaly, in Perl => is almost the same as the comma operator. It can be used as syntax sugar making it more clear when there is a key-value relation between two arguments, and also it automatically parses its lefthand argument (the key) as a string, so you don't need to quote it.

If you don't want to use that syntax, instead of writing:

 use Apache2::Const -compile => qw(FORBIDDEN OK);

you could write:

 use Apache2::Const "-compile", qw(FORBIDDEN OK);

and for parentheses-lovers:

 use Apache2::Const ("-compile", qw(FORBIDDEN OK));
  use Apache2::Const -compile => qw(:cmd_how);

The :cmd_how constants group is used in Apache2::Module::add() $cmds->args_how .

Apache2::Const::ITERATE2

Two arguments, the second occurs multiple times ( full description ).

  • since: 2.0.00

    Apache2::Const::RAW_ARGS

    The command will parse the command line itself ( full description ).

  • since: 2.0.00
      use Apache2::Const -compile => qw(:conn_keepalive);

    The :conn_keepalive constants group is used by the ( $c->keepalive ) method.

    Apache2::Const::CONN_CLOSE

    The connection will be closed at the end of the current HTTP request.

  • since: 2.0.00

    Apache2::Const::CONN_KEEPALIVE

    The connection will be kept alive at the end of the current HTTP request.

  • since: 2.0.00

    Apache2::Const::CONN_UNKNOWN

    The connection is at an unknown state, e.g., initialized but not open

  • since: 2.0.00
      use Apache2::Const -compile => qw(:context);

    The :context group is used by the $parms->check_cmd_context method.

      use Apache2::Const -compile => qw(:methods);

    The :methods constants group is used in conjunction with $r->method_number .

      use Apache2::Const -compile => qw(:options);

    The :options group contains constants corresponding to the Options configuration directive. For examples see: $r->allow_options .

      use Apache2::Const -compile => qw(:override);

    The :override group contains constants corresponding to the AllowOverride configuration directive. For examples see: $r->allow_options .

    Force directive to execute a command which would modify the configuration (like including another file, or IFModule )

  • since: 2.0.00
      use Apache2::Const -compile => qw(:platform);

    The :platform group is for constants that may differ from OS to OS.

      use Apache2::Const -compile => qw(:remotehost);

    The :remotehost constants group is is used by the $c->get_remote_host method.

      use Apache2::Const -compile => qw(:satisfy);

    The :satisfy constants group is used in conjunction with $r->satisfies .

      use Apache2::Const -compile => qw(:proxy);

    The :proxy constants group is used in conjunction with $r->proxyreq .

    modperl users mailing list.

  •