Porting notes: mod_perl1 to mod_perl2

Beatnik on 2006-04-17T14:40:36

A very short list of things I changed to port my app from mod_perl1 to mod_perl2. I didn't use any of the mod_perl2 funkyness but I did stick to Apache::Request (or Apache2::Request in this case).

  • To use OK, NOT FOUND and FORBIDDEN
    use Apache2::Const qw(FORBIDDEN NOT_FOUND OK);
    exports explicitly into namespace.
  • Use
    Apache2::RequestIO qw(print); 
    to allow 'print' in your code.
  • There is no
    $r->send_http_header
    but use
    $r->rflush
    to force sending headers.
  • To get the remote hostname, use
    $req->connection->get_remote_host
    instead of
    $req->get_remote_host
  • When setting cookies in a redirect, instead of
    $r->header_out->('Set-Cookie' => $cookie);
    use
    $r->err_headers_out->add('Set-Cookie' => $cookie);
  • When using HTTP file upload, load
    Apache2::Upload
    .
My main goal was simply to get an existing app working on mod_perl2.. and stay away from buckets and filters and all that (just for now). I did this is about 1.5 hours (once I understood what went where etc). I plan on adding an abstraction layer so that I can provide 1 version that'll support both mod_perl versions..