CGI::Struct::XS(3) Build structures from CGI data. Fast.


This module is XS implementation of CGI::Struct. It's fully compatible with CGI::Struct, except for error messages. "CGI::Struct::XS" is 3-15 (5-25 with dclone disabled) times faster than original module.


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


  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 };



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

The only exported function is "build_cgi_struct". It has three arguments:

HashRef with input values. Typicaly this is CGI or Plack params hashref
ArrayRef to store error messages. If it's not defined all parsing errors will be sielently discarded.
HashRef with parsing optiosn

Following options are supported:

Treat dot as ordinary character, not hash delimeter
Split input values by "\\0" character, useful for old CGI libraries
Store deep clone of value, instead of original value. This opion increase memory consumsion and slows parsing. It's recomended to disable dclone, because in most cases CGI params are used as read-only variables.