Mod perl2 conversion

From Dreamwidth Notes
Jump to: navigation, search

Here's a quick and dirty guide to things you will need to watch for when touching files and how to help us convert everything to Apache 2 / mod_perl 2 compatibility.

The Request Object

Never call Apache->request. If you need the request object, use BML::get_request() which will do the Right Thing to return the appropriate request object for you to mess with.

$ENV{LJHOME} is Dead

You should use $LJ::HOME instead. (Caveat: if you're writing a command line tool, you may need to use the environment variable, depending on what libraries you load... but for web context, always use $LJ::HOME!)

Methods become Hashes

In a move that I don't particularly understand, now we must pluralize some things and treat most things like a hash. If you are used to this:

$r->header_in("Host")
$r->header_in("Host" => "bar");
$r->notes("Something")

Then you should now get used to this:

$r->headers_in->{Host};
$r->headers_in->{Host} = "bar";
$r->notes->{Something}

Not much of a change. This goes for all of the header calls: headers_in, headers_out, err_headers_in, err_headers_out, etc as well as notes and pnotes. There are probably other changes I've missed that do this too.

$r->send_http_header defunct?

I've yet to figure out a replacement for this function. It seems to not be required anymore? The modules seem to do the right thing, at least in all of the cases I've tried, without ever calling this.

...?

I'm sure I'm missing something. But at this point, if you want to start grepping through dw-free for header_in, send_http_header, notes, etc and then start fixing it, go for it! It's appreciated, as there are still many files that have these.

As a second/other thought, I've been debating creating an LJ::Request object that we can use instead of Apache2::RequestRec (or whatever it is). That way, if we ever need to change the way something works (i.e. upgrade to Apache 2.2 / mod_perl 2.2?) then we can change that one module.

Opinions and discussion are welcome, of course!

(Imported from http://community.stage2.dreamwidth.org/dw_dev/630.html)