The manakai project

Web::URL::Encoding

URL percent encoding and application/x-www-form-urlencoded

SYNOPSIS

  use Web::URL::Encoding;
  warn percent_encode_c $text;
  warn serialize_form_urlencoded {
    $name => $value,
    $name => [$value1, $value2],
  };

DESCRIPTION

The Web::URL::Encoding module exports a function for the percent-encoding and the application/x-www-form-urlencoded encoding.

FUNCTIONS

The following functions are exported by default:

$bytes = percent_encode_c $text

Percent-encode the string, encoded in UTF-8. Anything other than [A-Za-z0-9_.-] are percent-encoded.

$text = percent_decode_c $bytes

Percent-decode the bytes and then decode as a UTF-8 string.

$bytes = percent_decode_b $bytes

Percent-decode the bytes and return the result bytes.

$bytes = oauth1_percent_encode_c $text

Percent-encode the string, encoded in UTF-8, for OAuth 1.0.

$bytes = oauth1_percent_encode_b $text

Percent-encode the bytes, for OAuth 1.0.

$bytes = serialize_form_urlencoded $params

Serialize a hash reference as an application/x-www-form-urlencoded bytes.

The argument must be a hash reference where keys are names of the encoded form data set and values are corresponding values.

If the value is undef, that key/value pair is ignored. If the value is an array reference, the items in the array are used as values of name/value pairs with same name. The order is preserved. The array can be empty.

The values are encoded in UTF-8.

SPECIFICATIONS

URL Standard <https://url.spec.whatwg.org/>.

RFC 5849, The OAuth 1.0 Protocol <https://tools.ietf.org/html/rfc5849>.

When a text is encoded in UTF-8, "UTF-8 encode" steps of the Encoding Standard MUST be used.

Encoding Standard <https://encoding.spec.whatwg.org/>.

SEE ALSO

SuikaWiki:percent-encoding <https://wiki.suikawiki.org/n/percent-encoding>.

HISTORY

The module partially derived from URL::PercentEncode <https://github.com/wakaba/perl-web-utils/blob/master/lib/URL/PercentEncode.pod> and Web::UserAgent::Functions and Web::UserAgent::OAuth from <https://github.com/wakaba/perl-web-useragent-functions>.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2009-2013 Hatena <https://www.hatena.ne.jp/>.

Copyright 2014-2016 Wakaba <wakaba@suikawiki.org>.

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