Well, mod_perl doesn't work that way. Everything in mod_perl gets structured in accordance to the Apache lifecycle, and that handlers are tied to the directory, file or location sections in your httpd.conf. So you can't just feed to another module and expect it to automagically figure out what to do woth it.

You almost certainly want to use inheritance instead.

package My::Upload; sub Upload { my ($class, $apr) = @_; $class->Add($_) foreach $apr->upload; } sub Add { my ($class, $apr) = @_; ... } package My::Doohickey; use base qw/My::Upload/; sub handler ($$) { my ($class, $r) = @_; my $apr = Apache::Request->instance($r, POST_MAX => 10*1024*1024, DISABLE_UPLOADS => 0); $class->Upload($apr) if $apr->upload; ... return OK; }

Notes:

1. Using Apache::Request->instance() reuses a previously created Apache::Request object if you've created one for the current request. Only problem is that it ignores the parameters after $r after the first invocation.

2. If you start out with something like:

sub handler ($$) { my ($class, $r) = @_; my $apr = Apache::Request->instance($r, POST_MAX => 10*1024*1024, DISABLE_UPLOADS => 0); ...

That will put the module name in $class, the Apache object in $r, and an Apache::Request object in $apr.

3. If the browser is on a dialup line, that server process will wait damn near forever for the uploaded file. This would be a cheap DoS attack on your server: just do 10 MB uploads to your server until your server starts thrashing. I generally limit uploads to the smallest I can get away with, and use a proxy Apache with a smaller footprint front end to buffer the requests.

HTH

update:As I think about it, something like My::Mod::Add->handler($r) might work. But very likely it won't ... I've never tried it and I have more interesting experiments to perform.


In reply to Re: mod_perl Apache::Request vs Apache->request by cleverett
in thread mod_perl Apache::Request vs Apache->request by drfrog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.