The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

URI::Query::FromHash - Construct a query string from a hash ref

SYNOPSIS

use utf8;
use URI::Query::FromHash;

my $query_string = hash2query {
   foo  => 'bar',
   baz  => [ qw/qux quux/ ],
   utf8 => '☃',
};

# or

my %args = ...;

my $query_string = hash2query %args;

DESCRIPTION

URI::Query::FromHash aims to be a fast, light query string constructor.

Inspired by Ruby on Rails' to_query hash method.

METHODS

hash2query

Accepts a hash ref of query parameters. The value of each parameter must either by a simple scalar or an array ref of simple scalars.

All strings are assumed to be UTF-8 decoded values.

BENCHMARK

$ perl -Ilib example/bench.pl
              Rate        uri hash2query
uri        24436/s         --       -59%
hash2query 59077/s       142%         --

SEE ALSO

URI

COPYRIGHT AND LICENSE

Copyright © 2016 by James Raspass

This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.