NAME
Text::QueryString - Fast QueryString Parser
SYNOPSIS
use Text::QueryString;
my $tqs = Text::QueryString->new;
my @query;
@query = $tqs->parse("foo=bar&bar=baz");
@query = $tqs->parse("foo=bar;bar=baz");
@query = $tqs->parse("foo"); # foo => ""
DESCRIPTION
WARNING: Still in ALPHA quality! Use at your own risk!
Text::QueryString is for when you need that speed to parse those punishingly annoying query strings that they send to your webapp. The reason this came to be is that we have encountered cases where we got hit by a performance degradation when moving from Apache based solution to Perl based solution.
Yes, normally just adding servers may be good, but since we were replacing old code to new code in hopes that things would get better, this performance degradation (while understandable because obviously C is much faster when working with simple string like query strings) really made us feel sad.
So here's Text::QueryString. By default the XS version is built and loaded. It will parse a given string, and run URI decoding on those values (URI decoding was completely stolen from Dan Kogai's URI::Escape::XS), and all is good.
It's your reponsibility to feed the results to whatever framework you're using. As an example: with Plack::Request
, you might monkey patch the query_parameter()
method like so:
use Plack::Request;
use Text::QueryString;
no strict 'refs';
my $tqs = Text::QueryString->new;
*Plack::Request::query_parameter = sub {
my $self = shift;
my $env = $self->env;
my $query = $env->{'plack.request.query'};
if ($query) {
return $query;
}
$env->{'plack.request.query'} = Hash::MultiValue->new($tqs->parse($env->{QUERY_STRING}));
};
There's a fallback pure-perl implementation in Text::QueryString::PP, but this is basically just there to provide a fallback when things just don't work. The code in Text::QueryString::PP was taken from URI::_query and slightly modified.
BENCHMARK
See tools/benchmark.pl for details:
Building Text-QueryString
Rate pp xs
pp 13964/s -- -76%
xs 59077/s 323% --
THANKS TO
Dan Kogai - For URI::Escape::XS
AUTHOR
Daisuke Maki <<daisuke@endeworks.jp
> >