in reply to Parse multipart/form-data with MIME::Parser

> CGI, which I've decided to not use

Good for you! What did you use instead?

There are modules that do most of the work for you. For example, using Plack::Request, which is still rather low level, you can just write:

#!/usr/bin/perl use strict; use warnings; use Plack::Request; sub { my $req = 'Plack::Request'->new(shift); my %method = ( GET => sub { [<DATA>] }, POST => sub { ['Hello ', $req->body_parameters->{text}] }); my $action = $method{ $req->method } or return [405, [Allow => join ', ', keys %method], []] +; return [200, ['Content-type' => 'text/html'], $action->()] } __DATA__ <html><body> <form method=post> Your name: <input name=text> <p> <input type=submit value=Submit> </form> </body></html>

Update: This code is wrong, see jcb's note.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Parse multipart/form-data with MIME::Parser
by jcb (Parson) on Apr 23, 2021 at 23:03 UTC

    Is there some kind of memoization magic in there or will that only return the form once, since it reads <DATA> but does not save the array anywhere?

      You are right, it doesn't work when you try to reload a page. Sorry.

      Here's a fix:

      my @template = <DATA>; sub { my $req = 'Plack::Request'->new(shift); my %method = ( GET => sub { \@template }, ...

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^2: Parse multipart/form-data with MIME::Parser
by Anonymous Monk on Apr 22, 2021 at 07:28 UTC
    I use nginx in the module, which is loaded by nginx, but I'm willing to add another use function since the most that the nginx module can do related to the problem is to display the related header part, and I don't feel like rewriting everything for a PSGI server or adding another full-fledged engine just to do one thing.