.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" 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" '' . ds C` . ds C' '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. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" 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 "2014-10-17" "perl v5.20.1" "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 $str = \*(Aqtest=23\*(Aq; \& my $escaped = url_escape $str; \& 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, which can be imported individually. .SS "b64_decode" .IX Subsection "b64_decode" .Vb 1 \& my $bytes = b64_decode $b64; .Ve .PP Base64 decode bytes. .SS "b64_encode" .IX Subsection "b64_encode" .Vb 2 \& my $b64 = b64_encode $bytes; \& my $b64 = b64_encode $bytes, "\en"; .Ve .PP Base64 encode bytes, the line ending defaults to a newline. .SS "camelize" .IX Subsection "camelize" .Vb 1 \& my $camelcase = camelize $snakecase; .Ve .PP Convert snake_case string to CamelCase 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 .SS "class_to_file" .IX Subsection "class_to_file" .Vb 1 \& my $file = class_to_file \*(AqFoo::Bar\*(Aq; .Ve .PP Convert a class name to a file. .PP .Vb 2 \& # "foo_bar" \& class_to_file \*(AqFoo::Bar\*(Aq; \& \& # "foobar" \& class_to_file \*(AqFOO::Bar\*(Aq; \& \& # "foo_bar" \& class_to_file \*(AqFooBar\*(Aq; \& \& # "foobar" \& class_to_file \*(AqFOOBar\*(Aq; .Ve .SS "class_to_path" .IX Subsection "class_to_path" .Vb 1 \& my $path = class_to_path \*(AqFoo::Bar\*(Aq; .Ve .PP Convert class name to path. .PP .Vb 2 \& # "Foo/Bar.pm" \& class_to_path \*(AqFoo::Bar\*(Aq; \& \& # "FooBar.pm" \& class_to_path \*(AqFooBar\*(Aq; .Ve .SS "decamelize" .IX Subsection "decamelize" .Vb 1 \& my $snakecase = decamelize $camelcase; .Ve .PP Convert CamelCase 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 .SS "decode" .IX Subsection "decode" .Vb 1 \& my $chars = decode \*(AqUTF\-8\*(Aq, $bytes; .Ve .PP Decode bytes to characters and return \f(CW\*(C`undef\*(C'\fR if decoding failed. .SS "deprecated" .IX Subsection "deprecated" .Vb 1 \& deprecated \*(Aqfoo is DEPRECATED in favor of bar\*(Aq; .Ve .PP Warn about deprecated feature from perspective of caller. You can also set the \&\f(CW\*(C`MOJO_FATAL_DEPRECATIONS\*(C'\fR environment variable to make them die instead. .SS "dumper" .IX Subsection "dumper" .Vb 1 \& my $perl = dumper {some => \*(Aqdata\*(Aq}; .Ve .PP Dump a Perl data structure with Data::Dumper. .SS "encode" .IX Subsection "encode" .Vb 1 \& my $bytes = encode \*(AqUTF\-8\*(Aq, $chars; .Ve .PP Encode characters to bytes. .SS "hmac_sha1_sum" .IX Subsection "hmac_sha1_sum" .Vb 1 \& my $checksum = hmac_sha1_sum $bytes, \*(Aqpassw0rd\*(Aq; .Ve .PP Generate \s-1HMAC\-SHA1\s0 checksum for bytes. .SS "html_unescape" .IX Subsection "html_unescape" .Vb 1 \& my $str = html_unescape $escaped; .Ve .PP Unescape all \s-1HTML\s0 entities in string. .SS "md5_bytes" .IX Subsection "md5_bytes" .Vb 1 \& my $checksum = md5_bytes $bytes; .Ve .PP Generate binary \s-1MD5\s0 checksum for bytes. .SS "md5_sum" .IX Subsection "md5_sum" .Vb 1 \& my $checksum = md5_sum $bytes; .Ve .PP Generate \s-1MD5\s0 checksum for bytes. .SS "monkey_patch" .IX Subsection "monkey_patch" .Vb 2 \& monkey_patch $package, foo => sub {...}; \& monkey_patch $package, foo => sub {...}, bar => sub {...}; .Ve .PP Monkey patch functions into package. .PP .Vb 4 \& monkey_patch \*(AqMyApp\*(Aq, \& one => sub { say \*(AqOne!\*(Aq }, \& two => sub { say \*(AqTwo!\*(Aq }, \& three => sub { say \*(AqThree!\*(Aq }; .Ve .SS "punycode_decode" .IX Subsection "punycode_decode" .Vb 1 \& my $str = punycode_decode $punycode; .Ve .PP Punycode decode string as described in \&\s-1RFC 3492\s0 . .SS "punycode_encode" .IX Subsection "punycode_encode" .Vb 1 \& my $punycode = punycode_encode $str; .Ve .PP Punycode encode string as described in \&\s-1RFC 3492\s0 . .SS "quote" .IX Subsection "quote" .Vb 1 \& my $quoted = quote $str; .Ve .PP Quote string. .SS "secure_compare" .IX Subsection "secure_compare" .Vb 1 \& my $bool = secure_compare $str1, $str2; .Ve .PP Constant time comparison algorithm to prevent timing attacks. .SS "sha1_bytes" .IX Subsection "sha1_bytes" .Vb 1 \& my $checksum = sha1_bytes $bytes; .Ve .PP Generate binary \s-1SHA1\s0 checksum for bytes. .SS "sha1_sum" .IX Subsection "sha1_sum" .Vb 1 \& my $checksum = sha1_sum $bytes; .Ve .PP Generate \s-1SHA1\s0 checksum for bytes. .SS "slurp" .IX Subsection "slurp" .Vb 1 \& my $bytes = slurp \*(Aq/etc/passwd\*(Aq; .Ve .PP Read all data at once from file. .SS "split_header" .IX Subsection "split_header" .Vb 1 \& my $tree = split_header \*(Aqfoo="bar baz"; test=123, yada\*(Aq; .Ve .PP Split \s-1HTTP\s0 header value. .PP .Vb 2 \& # "one" \& split_header(\*(Aqone; two="three four", five=six\*(Aq)\->[0][0]; \& \& # "three four" \& split_header(\*(Aqone; two="three four", five=six\*(Aq)\->[0][3]; \& \& # "five" \& split_header(\*(Aqone; two="three four", five=six\*(Aq)\->[1][0]; .Ve .SS "spurt" .IX Subsection "spurt" .Vb 1 \& $bytes = spurt $bytes, \*(Aq/etc/passwd\*(Aq; .Ve .PP Write all data at once to file. .SS "squish" .IX Subsection "squish" .Vb 1 \& my $squished = squish $str; .Ve .PP Trim whitespace characters from both ends of string and then change all consecutive groups of whitespace into one space each. .SS "steady_time" .IX Subsection "steady_time" .Vb 1 \& my $time = steady_time; .Ve .PP High resolution time elapsed from an arbitrary fixed point in the past, resilient to time jumps if a monotonic clock is available through Time::HiRes. .SS "tablify" .IX Subsection "tablify" .Vb 1 \& my $table = tablify [[\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq], [\*(Aqbaz\*(Aq, \*(Aqyada\*(Aq]]; .Ve .PP Row-oriented generator for text tables. .PP .Vb 2 \& # "foo bar\enyada yada\enbaz yada\en" \& tablify [[\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq], [\*(Aqyada\*(Aq, \*(Aqyada\*(Aq], [\*(Aqbaz\*(Aq, \*(Aqyada\*(Aq]]; .Ve .SS "trim" .IX Subsection "trim" .Vb 1 \& my $trimmed = trim $str; .Ve .PP Trim whitespace characters from both ends of string. .SS "unindent" .IX Subsection "unindent" .Vb 1 \& my $unindented = unindent $str; .Ve .PP Unindent multiline string. .SS "unquote" .IX Subsection "unquote" .Vb 1 \& my $str = unquote $quoted; .Ve .PP Unquote string. .SS "url_escape" .IX Subsection "url_escape" .Vb 2 \& my $escaped = url_escape $str; \& my $escaped = url_escape $str, \*(Aq^A\-Za\-z0\-9\e\-._~\*(Aq; .Ve .PP Percent encode unsafe characters in string as described in \&\s-1RFC 3986\s0 , the pattern used defaults to \&\f(CW\*(C`^A\-Za\-z0\-9\e\-._~\*(C'\fR. .SS "url_unescape" .IX Subsection "url_unescape" .Vb 1 \& my $str = url_unescape $escaped; .Ve .PP Decode percent encoded characters in string as described in \&\s-1RFC 3986\s0 . .SS "xml_escape" .IX Subsection "xml_escape" .Vb 1 \& my $escaped = xml_escape $str; .Ve .PP Escape unsafe 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. .SS "xor_encode" .IX Subsection "xor_encode" .Vb 1 \& my $encoded = xor_encode $str, $key; .Ve .PP \&\s-1XOR\s0 encode string with variable length key. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .