
Mojo::Util - Portable utility functions

use Mojo::Util qw(b64_encode url_escape url_unescape); my $string = 'test=23'; my $escaped = url_escape $string; say url_unescape $escaped; say b64_encode $escaped, '';

Mojo::Util provides portable utility functions for Mojo.

Mojo::Util implements the following functions.
b64_decodemy $string = b64_decode $b64;
Base64 decode string.
b64_encodemy $b64 = b64_encode $string; my $b64 = b64_encode $string, "\n";
Base64 encode string, the line ending defaults to a newline.
camelizemy $camelcase = camelize $snakecase;
Convert snake case string to camel case and replace - with ::.
# "FooBar" camelize 'foo_bar'; # "FooBar::Baz" camelize 'foo_bar-baz'; # "FooBar::Baz" camelize 'FooBar::Baz';
decamelizemy $snakecase = decamelize $camelcase;
Convert camel case string to snake case and replace :: with -.
# "foo_bar" decamelize 'FooBar'; # "foo_bar-baz" decamelize 'FooBar::Baz'; # "foo_bar-baz" decamelize 'foo_bar-baz';
decodemy $chars = decode 'UTF-8', $bytes;
Decode bytes to characters.
encodemy $bytes = encode 'UTF-8', $chars;
Encode characters to bytes.
get_linemy $line = get_line \$string;
Extract whole line from string or return undef. Lines are expected to end with 0x0d 0x0a or 0x0a.
hmac_md5_summy $checksum = hmac_md5_sum $string, 'passw0rd';
Generate HMAC-MD5 checksum for string.
hmac_sha1_summy $checksum = hmac_sha1_sum $string, 'passw0rd';
Generate HMAC-SHA1 checksum for string.
html_escapemy $escaped = html_escape $string; my $escaped = html_escape $string, '^\n\r\t !#$%(-;=?-~';
Escape unsafe characters in string with HTML5 entities, the pattern used defaults to ^\n\r\t !#$%(-;=?-~.
html_unescapemy $string = html_unescape $escaped;
Unescape all HTML5 entities in string.
md5_bytesmy $checksum = md5_bytes $string;
Generate binary MD5 checksum for string.
md5_summy $checksum = md5_sum $string;
Generate MD5 checksum for string.
punycode_decodemy $string = punycode_decode $punycode;
Punycode decode string.
punycode_encodemy $punycode = punycode_encode $string;
Punycode encode string.
quotemy $quoted = quote $string;
Quote string.
qp_decodemy $string = qp_decode $qp;
Quoted Printable decode string.
qp_encodemy $qp = qp_encode $string;
Quoted Printable encode string.
secure_comparemy $success = secure_compare $string1, $string2;
Constant time comparison algorithm to prevent timing attacks.
sha1_bytesmy $checksum = sha1_bytes $string;
Generate binary SHA1 checksum for string.
sha1_summy $checksum = sha1_sum $string;
Generate SHA1 checksum for string.
trimmy $trimmed = trim $string;
Trim whitespace characters from both ends of string.
unquotemy $string = unquote $quoted;
Unquote string.
url_escapemy $escaped = url_escape $string; my $escaped = url_escape $string, '^A-Za-z0-9\-._~';
Percent-encode unsafe characters in string, the pattern used defaults to ^A-Za-z0-9\-._~.
url_unescapemy $string = url_unescape $escaped;
Decode percent-encoded characters in string.
xml_escapemy $escaped = xml_escape $string;
Escape only the characters &, <, >, " and ' in string, this is a much faster version of html_escape.
