Perl Documentation
NAME
AxKit2::Utils - web related helper functions
DESCRIPTION
This package is a collection of utility functions that are commonly used in web applications.
API
uri_encode string
URI-encode the given string. It is not suitable for full URIs, as it encodes almost every character not guaranteed to be safe in every part of an URI, including the question mark, for example.
uri_decode string [, is_query]
URI-decode the given string. If is_query
is true, slightly different decoding rules
are used which apply to the query string part of an URI.
Note that the result is a byte string since URIs do not contain charset information. If
your applications follows recommended best practice of UTF-8 URIs, pass the result
through Encode::decode_utf8
to get a regular Perl string. Otherwise, use ustr
if
you are using legacy encodings.
uri_normalize string
Converts the given string to a canonical form according to RFC2396. Only exactly those chars will be %-encoded that need it, which allows easier pattern matches.
It will also strip "./" and "../" path segments as per Section 5.2 of the RFC.
Note that it only handles non-opaque URIs correctly.
utf8_chr char
Converts the given character to a UTF-8 byte sequence.
http_date [ timestamp ]
Creates a HTTP-compatible date string. If no timestamp is given, the current time is used.
xml_escape string
XML-escapes the given string. The result is safe to use as plain text anywhere in an XML document.
bytelength string
Returns the length of the string in bytes, not characters.
html_to_dom string
Parses an HTML string and returns a UTF-8 encoded XML::LibXML::Document DOM.
ustr bytestring
Tries to autdetect the input string's encoding by trying several encodings in order until one is able to decode the string without errors. Falls back to UTF-8 with substitution chars. Always returns a Perl unicode string. If the input is already a Perl unicode string, it will be returned as-is.
Which encodings to try can be specified with global configuration setting Encodings
.
Default is Encodings UTF-8 ISO-8859-15
.
random
Returns a cryptographically secure pseudo-random value, if possible. This depends on
Math::Random::MT::Auto, and will fall back to plain rand()
if that's not
available.