.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" 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 >0, 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Mojo::Util 3pm" .TH Mojo::Util 3pm "2017-01-24" "perl v5.24.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 \f(CW\*(C`snake_case\*(C'\fR string to \f(CW\*(C`CamelCase\*(C'\fR 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, as used by \f(CW%INC\fR. .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 \f(CW\*(C`CamelCase\*(C'\fR string to \f(CW\*(C`snake_case\*(C'\fR 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, or 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 "extract_usage" .IX Subsection "extract_usage" .Vb 2 \& my $usage = extract_usage; \& my $usage = extract_usage \*(Aq/home/sri/foo.pod\*(Aq; .Ve .PP Extract usage message from the \s-1SYNOPSIS\s0 section of a file containing \s-1POD\s0 documentation, defaults to using the file this function was called from. .PP .Vb 2 \& # "Usage: APPLICATION test [OPTIONS]\en" \& extract_usage; \& \& =head1 SYNOPSIS \& \& Usage: APPLICATION test [OPTIONS] \& \& =cut .Ve .SS "getopt" .IX Subsection "getopt" .Vb 12 \& getopt \& \*(AqH|headers=s\*(Aq => \emy @headers, \& \*(Aqt|timeout=i\*(Aq => \emy $timeout, \& \*(Aqv|verbose\*(Aq => \emy $verbose; \& getopt $array, \& \*(AqH|headers=s\*(Aq => \emy @headers, \& \*(Aqt|timeout=i\*(Aq => \emy $timeout, \& \*(Aqv|verbose\*(Aq => \emy $verbose; \& getopt $array, [\*(Aqpass_through\*(Aq], \& \*(AqH|headers=s\*(Aq => \emy @headers, \& \*(Aqt|timeout=i\*(Aq => \emy $timeout, \& \*(Aqv|verbose\*(Aq => \emy $verbose; .Ve .PP Extract options from an array reference with Getopt::Long, but without changing its global configuration, defaults to using \f(CW@ARGV\fR. The configuration options \f(CW\*(C`no_auto_abbrev\*(C'\fR and \f(CW\*(C`no_ignore_case\*(C'\fR are enabled by default. .PP .Vb 3 \& # Extract "charset" option \& getopt [\*(Aq\-\-charset\*(Aq, \*(AqUTF\-8\*(Aq], \*(Aqcharset=s\*(Aq => \emy $charset; \& say $charset; .Ve .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. .PP .Vb 2 \& # "11cedfd5ec11adc0ec234466d8a0f2a83736aa68" \& hmac_sha1_sum \*(Aqfoo\*(Aq, \*(Aqpassw0rd\*(Aq; .Ve .SS "html_unescape" .IX Subsection "html_unescape" .Vb 1 \& my $str = html_unescape $escaped; .Ve .PP Unescape all \s-1HTML\s0 entities in string. .PP .Vb 2 \& # "