Tatsuhiko Miyagawa's Blog

Hash::MultiValue now has ->from_mixed

December 17, 2009

So I blogged why params() sucks but there’re already applications and libraries that do this: Catalyst and CGI::Deurl for instance. Changing the behavior of these libraries or core framework would break the existing code, even worse, mostly silently (because ref $params->{foo} eq 'ARRAY' would silently return false).

Hash::MultiValue 0.03 is now shipped with from_mixed method, so you can easily create the MultiValue hash out of those objects:

use CGI::Deurl;
use Hash::MultiValue;

my $params = CGI::Deurl::parse_query_string($query_string);
$params = Hash::MultiValue->from_mixed($params);

my $foo = $params->{foo}; # last entry
my @foo = $params->get_all('foo'); # all