logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Coding & Scripting Corner View previous topic :: View next topic
Reply to topic   Topic: Apache2::RequestRec
Author
shug94



Joined: 27 Aug 2009
Posts: 9

PostPosted: Wed 02 Sep '09 12:33    Post subject: Apache2::RequestRec Reply with quote

I have a perl script, and I want to retrieve the method used to make the HTTP Request that caused this Perl script to execute.

It seems to me like the following bit of code would do it:
my $method = $r->method();

This code is described in:
http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_method_

However, my problem is (as a bit of an Apache Server, and Perl newb), that it does not describe how to get the $r variable, which seems to be an instance of Apache2::RequestRec. Do I retrieve it from somewhere, is it passed into my program, or do I have to instantiate it?

Any help would be appreciated.
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Wed 02 Sep '09 21:25    Post subject: Reply with quote

# Objects are a trip .. harder to explain than understand for me.

# $r->method() returns a value, $r is a pointer to the object
# so in the example you linked to, $method is equal the value returned by $r->method()
# thier use of $method could be confusing, so we'll change it.

# what's the current request (GET/POST/etc)?
$myvalue= $r->method();

# $myvalue is now going to contain either "GET", "POST", "HEAD", "WHATEVER"
# if form content was posted, $myvalue is going to = "POST"

# If the current method is set to POST, and you now set it to GET
$myvalue = $r->method("GET");

# the docs state that it returns the prior setting so $myvalue is going to = "POST" still.

# Let's now change it to HEAD.

$myvalue = $r->method("HEAD");
# $myvalue is going to = "GET", the prior setting.

$myvalue = $r->method();
# $myvalue is going to = "HEAD" the current setting.

.
Back to top


Reply to topic   Topic: Apache2::RequestRec View previous topic :: View next topic
Post new topic   Forum Index -> Coding & Scripting Corner