.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojo::Util 3pm" .TH Mojo::Util 3pm "2012-09-05" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::Util \- Portable utility functions .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::Util qw(b64_encode url_escape url_unescape); \& \& my $string = \*(Aqtest=23\*(Aq; \& my $escaped = url_escape $string; \& say url_unescape $escaped; \& say b64_encode $escaped, \*(Aq\*(Aq; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::Util provides portable utility functions for Mojo. .SH "FUNCTIONS" .IX Header "FUNCTIONS" Mojo::Util implements the following functions. .ie n .SS """b64_decode""" .el .SS "\f(CWb64_decode\fP" .IX Subsection "b64_decode" .Vb 1 \& my $string = b64_decode $b64; .Ve .PP Base64 decode string. .ie n .SS """b64_encode""" .el .SS "\f(CWb64_encode\fP" .IX Subsection "b64_encode" .Vb 2 \& my $b64 = b64_encode $string; \& my $b64 = b64_encode $string, "\en"; .Ve .PP Base64 encode string, the line ending defaults to a newline. .ie n .SS """camelize""" .el .SS "\f(CWcamelize\fP" .IX Subsection "camelize" .Vb 1 \& my $camelcase = camelize $snakecase; .Ve .PP Convert snake case string to camel case and replace \f(CW\*(C`\-\*(C'\fR with \f(CW\*(C`::\*(C'\fR. .PP .Vb 2 \& # "FooBar" \& camelize \*(Aqfoo_bar\*(Aq; \& \& # "FooBar::Baz" \& camelize \*(Aqfoo_bar\-baz\*(Aq; \& \& # "FooBar::Baz" \& camelize \*(AqFooBar::Baz\*(Aq; .Ve .ie n .SS """decamelize""" .el .SS "\f(CWdecamelize\fP" .IX Subsection "decamelize" .Vb 1 \& my $snakecase = decamelize $camelcase; .Ve .PP Convert camel case string to snake case and replace \f(CW\*(C`::\*(C'\fR with \f(CW\*(C`\-\*(C'\fR. .PP .Vb 2 \& # "foo_bar" \& decamelize \*(AqFooBar\*(Aq; \& \& # "foo_bar\-baz" \& decamelize \*(AqFooBar::Baz\*(Aq; \& \& # "foo_bar\-baz" \& decamelize \*(Aqfoo_bar\-baz\*(Aq; .Ve .ie n .SS """decode""" .el .SS "\f(CWdecode\fP" .IX Subsection "decode" .Vb 1 \& my $chars = decode \*(AqUTF\-8\*(Aq, $bytes; .Ve .PP Decode bytes to characters. .ie n .SS """encode""" .el .SS "\f(CWencode\fP" .IX Subsection "encode" .Vb 1 \& my $bytes = encode \*(AqUTF\-8\*(Aq, $chars; .Ve .PP Encode characters to bytes. .ie n .SS """get_line""" .el .SS "\f(CWget_line\fP" .IX Subsection "get_line" .Vb 1 \& my $line = get_line \e$string; .Ve .PP Extract whole line from string or return \f(CW\*(C`undef\*(C'\fR. Lines are expected to end with \f(CW\*(C`0x0d 0x0a\*(C'\fR or \f(CW0x0a\fR. .ie n .SS """hmac_md5_sum""" .el .SS "\f(CWhmac_md5_sum\fP" .IX Subsection "hmac_md5_sum" .Vb 1 \& my $checksum = hmac_md5_sum $string, \*(Aqpassw0rd\*(Aq; .Ve .PP Generate \s-1HMAC\-MD5\s0 checksum for string. .ie n .SS """hmac_sha1_sum""" .el .SS "\f(CWhmac_sha1_sum\fP" .IX Subsection "hmac_sha1_sum" .Vb 1 \& my $checksum = hmac_sha1_sum $string, \*(Aqpassw0rd\*(Aq; .Ve .PP Generate \s-1HMAC\-SHA1\s0 checksum for string. .ie n .SS """html_escape""" .el .SS "\f(CWhtml_escape\fP" .IX Subsection "html_escape" .Vb 2 \& my $escaped = html_escape $string; \& my $escaped = html_escape $string, \*(Aq^\en\er\et !#$%(\-;=?\-~\*(Aq; .Ve .PP Escape unsafe characters in string with \s-1HTML5\s0 entities, the pattern used defaults to \f(CW\*(C`^\en\er\et !#$%(\-;=?\-~\*(C'\fR. .ie n .SS """html_unescape""" .el .SS "\f(CWhtml_unescape\fP" .IX Subsection "html_unescape" .Vb 1 \& my $string = html_unescape $escaped; .Ve .PP Unescape all \s-1HTML5\s0 entities in string. .ie n .SS """md5_bytes""" .el .SS "\f(CWmd5_bytes\fP" .IX Subsection "md5_bytes" .Vb 1 \& my $checksum = md5_bytes $string; .Ve .PP Generate binary \s-1MD5\s0 checksum for string. .ie n .SS """md5_sum""" .el .SS "\f(CWmd5_sum\fP" .IX Subsection "md5_sum" .Vb 1 \& my $checksum = md5_sum $string; .Ve .PP Generate \s-1MD5\s0 checksum for string. .ie n .SS """punycode_decode""" .el .SS "\f(CWpunycode_decode\fP" .IX Subsection "punycode_decode" .Vb 1 \& my $string = punycode_decode $punycode; .Ve .PP Punycode decode string. .ie n .SS """punycode_encode""" .el .SS "\f(CWpunycode_encode\fP" .IX Subsection "punycode_encode" .Vb 1 \& my $punycode = punycode_encode $string; .Ve .PP Punycode encode string. .ie n .SS """quote""" .el .SS "\f(CWquote\fP" .IX Subsection "quote" .Vb 1 \& my $quoted = quote $string; .Ve .PP Quote string. .ie n .SS """qp_decode""" .el .SS "\f(CWqp_decode\fP" .IX Subsection "qp_decode" .Vb 1 \& my $string = qp_decode $qp; .Ve .PP Quoted Printable decode string. .ie n .SS """qp_encode""" .el .SS "\f(CWqp_encode\fP" .IX Subsection "qp_encode" .Vb 1 \& my $qp = qp_encode $string; .Ve .PP Quoted Printable encode string. .ie n .SS """secure_compare""" .el .SS "\f(CWsecure_compare\fP" .IX Subsection "secure_compare" .Vb 1 \& my $success = secure_compare $string1, $string2; .Ve .PP Constant time comparison algorithm to prevent timing attacks. .ie n .SS """sha1_bytes""" .el .SS "\f(CWsha1_bytes\fP" .IX Subsection "sha1_bytes" .Vb 1 \& my $checksum = sha1_bytes $string; .Ve .PP Generate binary \s-1SHA1\s0 checksum for string. .ie n .SS """sha1_sum""" .el .SS "\f(CWsha1_sum\fP" .IX Subsection "sha1_sum" .Vb 1 \& my $checksum = sha1_sum $string; .Ve .PP Generate \s-1SHA1\s0 checksum for string. .ie n .SS """trim""" .el .SS "\f(CWtrim\fP" .IX Subsection "trim" .Vb 1 \& my $trimmed = trim $string; .Ve .PP Trim whitespace characters from both ends of string. .ie n .SS """unquote""" .el .SS "\f(CWunquote\fP" .IX Subsection "unquote" .Vb 1 \& my $string = unquote $quoted; .Ve .PP Unquote string. .ie n .SS """url_escape""" .el .SS "\f(CWurl_escape\fP" .IX Subsection "url_escape" .Vb 2 \& my $escaped = url_escape $string; \& my $escaped = url_escape $string, \*(Aq^A\-Za\-z0\-9\e\-._~\*(Aq; .Ve .PP Percent-encode unsafe characters in string, the pattern used defaults to \&\f(CW\*(C`^A\-Za\-z0\-9\e\-._~\*(C'\fR. .ie n .SS """url_unescape""" .el .SS "\f(CWurl_unescape\fP" .IX Subsection "url_unescape" .Vb 1 \& my $string = url_unescape $escaped; .Ve .PP Decode percent-encoded characters in string. .ie n .SS """xml_escape""" .el .SS "\f(CWxml_escape\fP" .IX Subsection "xml_escape" .Vb 1 \& my $escaped = xml_escape $string; .Ve .PP Escape only the characters \f(CW\*(C`&\*(C'\fR, \f(CW\*(C`<\*(C'\fR, \f(CW\*(C`>\*(C'\fR, \f(CW\*(C`"\*(C'\fR and \f(CW\*(C`\*(Aq\*(C'\fR in string, this is a much faster version of \f(CW\*(C`html_escape\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .