You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs-cvs@perl.apache.org by ge...@apache.org on 2003/07/31 17:01:56 UTC
cvs commit: modperl-docs/src/docs/2.0/user/config custom.pod
geoff 2003/07/31 08:01:56
Modified: src/docs/2.0/user/config custom.pod
Log:
add cmd_data and $parms->info docs
Submitted by: geoff
Revision Changes Path
1.6 +50 -0 modperl-docs/src/docs/2.0/user/config/custom.pod
Index: custom.pod
===================================================================
RCS file: /home/cvs/modperl-docs/src/docs/2.0/user/config/custom.pod,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- custom.pod 20 Feb 2003 02:50:02 -0000 1.5
+++ custom.pod 31 Jul 2003 15:01:56 -0000 1.6
@@ -266,6 +266,56 @@
be a string based on the directive's I<L<name|/C_name_>> and
I<L<args_how|/C_args_how_>> attributes.
+=head3 C<cmd_data>
+
+Sometimes it is useful to pass information back to the directive
+handler callback. For instance, if you use the I<func> parameter
+to specify the same callback for two different directives you
+might want to know which directive is being called currently.
+To do this, you can use the I<cmd_data> parameter, which allows
+you to store arbitrary strings for later retrieval from your
+directive handler. For instance.
+
+ our @APACHE_MODULE_COMMANDS = (
+ {
+ name => '<Location',
+ # func defaults to Redirect()
+ req_override => Apache::RSRC_CONF,
+ args_how => Apache::RAW_ARGS,
+ },
+ {
+ name => '<LocationMatch',
+ func => Redirect,
+ req_override => Apache::RSRC_CONF,
+ args_how => Apache::RAW_ARGS,
+ cmd_data => '1',
+ },
+ );
+
+Here, we are using the C<Location()> function to process both
+the C<Location> and C<LocationMatch> directives. In the
+C<Location()> callback we can check the data in the I<cmd_data> slot
+to see whether the directive being processed is C<LocationMatch>
+and alter our logic accordingly. How? Through the
+C<info()> method exposed by the C<Apache::CmdParms> class.
+
+ use Apache::CmdParms ();
+
+ ...
+
+ sub Location {
+
+ my ($cfg, $parms, $data) = @_;
+
+ # see if we were called via LocationMatch
+ my $regex = $parms->info;
+
+ ...
+ }
+
+In case you are wondering, C<Location> and C<LocationMatch> were
+chosen for a reason - this is exactly how httpd core handles these
+two directives.
=head2 Directive Scope Definition Constants
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-cvs-help@perl.apache.org
Re: cvs commit: modperl-docs/src/docs/2.0/user/config custom.pod
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>
>> Thanks, Geoff!
>>
>> There are two minor problems with the code section formatting.
>> Remember that code sections are rendered as <pre></pre>.
>>
>>> + use Apache::CmdParms ();
>>> +
>>
>>
>> ^^
>> So, we need to avoid empty lines in the code
>
>
> you don't really mean to remove all the empty lines from the code, do
> you? <pre> preserves empty lines (at least in modern browsers - that's
> how I've been formatting my perl.com stuff and it works just fine). and
> I don't see the difference between what I put in and the
> Apache::MyParameters stuff you had earlier in the doc.
Look at: http://perl.apache.org/docs/2.0/user/config/custom.html#C_cmd_data_
you will see what I mean (the | line on the left of the box is discontinued.)
I didn't say to remove empty lines, but to do: s|^| |' (that's two leading
spaces).
>>> + sub Location {
>>>
>>> +
>>> + my ($cfg, $parms, $data) = @_;
>>>
>>> +
>> second avoid long lines, above you had 100 space chars.
>
>
> chalk that up to editor woes (I'm on a new box and still trying to tweak
> my vi settings :)
;)
Do you want me to fix that?
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-dev-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-dev-help@perl.apache.org
Re: cvs commit: modperl-docs/src/docs/2.0/user/config custom.pod
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> Thanks, Geoff!
>
> There are two minor problems with the code section formatting. Remember
> that code sections are rendered as <pre></pre>.
>
>> + use Apache::CmdParms ();
>> +
>
> ^^
> So, we need to avoid empty lines in the code
you don't really mean to remove all the empty lines from the code, do you?
<pre> preserves empty lines (at least in modern browsers - that's how I've
been formatting my perl.com stuff and it works just fine). and I don't see
the difference between what I put in and the Apache::MyParameters stuff you
had earlier in the doc.
> ( I always take the
> original code and run it through 'perl -pi -e 's|^| |' file') so the
> code section is rendered as a single box.
I'll remember that.
>
>> + ...
>> +
>> + sub Location {
>>
>> +
>> + my ($cfg, $parms, $data) = @_;
>>
>> +
>
>
>
> second avoid long lines, above you had 100 space chars.
chalk that up to editor woes (I'm on a new box and still trying to tweak my
vi settings :)
> trying to keep
> it under 74-80 is a good idea. and there is no need for 100 spaces, when
> 2 will do ;)
indeed :)
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-dev-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-dev-help@perl.apache.org
Re: cvs commit: modperl-docs/src/docs/2.0/user/config custom.pod
Posted by Stas Bekman <st...@stason.org>.
geoff@apache.org wrote:
> geoff 2003/07/31 08:01:56
>
> Modified: src/docs/2.0/user/config custom.pod
> Log:
> add cmd_data and $parms->info docs
> Submitted by: geoff
>
> Revision Changes Path
> 1.6 +50 -0 modperl-docs/src/docs/2.0/user/config/custom.pod
>
> Index: custom.pod
Thanks, Geoff!
There are two minor problems with the code section formatting. Remember that
code sections are rendered as <pre></pre>.
> + use Apache::CmdParms ();
> +
^^
So, we need to avoid empty lines in the code ( I always take the original code
and run it through 'perl -pi -e 's|^| |' file') so the code section is
rendered as a single box.
> + ...
> +
> + sub Location {
> +
> + my ($cfg, $parms, $data) = @_;
> +
second avoid long lines, above you had 100 space chars. trying to keep it
under 74-80 is a good idea. and there is no need for 100 spaces, when 2 will do ;)
Thanks.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
---------------------------------------------------------------------
To unsubscribe, e-mail: docs-dev-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-dev-help@perl.apache.org