CGI::Struct::XS(3pm)

πŸ’– CGI::Struct::XS πŸ’–

okay bestie so this is CGI::Struct::XS, a Perl module living in the User Contributed Perl Documentation section of the manual. It's the glow-up version of CGI::Struct, and it's fast.


✨ DESCRIPTION ✨

So basically, this module is the XS implementation of CGI::Struct. It is fully compatible with CGI::Struct β€” like, every single thing works the same β€” with exactly one exception: the error messages. Those are different. That's it.

And the speed? Not me being dramatic, but CGI::Struct::XS is 3-15 times faster than the original module β€” and 5-25 times faster when dclone is disabled. She ate. πŸ’…


🌸 SYNOPSIS 🌸

First vibe, with good old CGI:

use CGI;
use CGI::Struct::XS;
my $cgi = CGI->new;
my %params = $cgi->Vars;
my $struct = build_cgi_struct \%params;
...

Or, if you're a Plack girlie:

use Plack::Request;
use CGI::Struct::XS;

my $app_or_middleware = sub {
    my $env = shift; # PSGI env
    my $req = Plack::Request->new($env);
    my $errs = [];
    my $struct = build_cgi_struct $req->parameters, $errs, { dclone => 0 };
    ...
};

πŸ¦‹ FUNCTIONS πŸ¦‹

build_cgi_struct

$struct = build_cgi_struct \%params;

$struct = build_cgi_struct \%params, \@errs;

$struct = build_cgi_struct \%params, \@errs, \%conf;

The only function this module exports is build_cgi_struct, and she takes three arguments. Let's go through them one by one, no gatekeeping:

  • \%params β€” a HashRef stuffed with your input values. Usually this is a CGI params hashref or a Plack params hashref. Standard.
  • \@errs β€” an ArrayRef where error messages get stashed. If it's not defined, then every parsing error just gets silently discarded. Gone. Nothing to see here. πŸ™ˆ
  • \%conf β€” a HashRef with your parsing options. Details below, bestie.

the options, in list form ✨

  • nodot β€” treat the dot as an ordinary character, not as a hash delimiter.
  • nullsplit β€” split input values on the "\\0" character. This one's for you if you're dealing with old CGI libraries.
  • dclone β€” store a deep clone of the value instead of the original value. Heads up though: this option increases memory consumption and slows parsing down. The recommendation is to disable dclone, because in most cases CGI params get used as read-only variables anyway, so like... why clone? Not needed, babe.

πŸ‘‘ SEE ALSO πŸ‘‘

  • CGI::Struct

k that's the whole page, you're all caught up πŸ’–

This page came to you from perl v5.42.3, dated 2026-08-20, and it's the CGI::Struct::XS(3pm) page under User Contributed Perl Documentation. slay, go build some structs βœ¨πŸŽ€

πŸ“¦ where this page comes from