.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" 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 .. .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 .\" ======================================================================== .\" .IX Title "Mojo::ByteStream 3pm" .TH Mojo::ByteStream 3pm "2022-12-22" "perl v5.36.0" "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::ByteStream \- ByteStream .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::ByteStream; \& \& # Manipulate bytestream \& my $stream = Mojo::ByteStream\->new(\*(Aqfoo_bar_baz\*(Aq); \& say $stream\->camelize; \& \& # Chain methods \& my $stream = Mojo::ByteStream\->new(\*(Aqfoo bar baz\*(Aq)\->quote; \& $stream = $stream\->unquote\->encode(\*(AqUTF\-8\*(Aq)\->b64_encode(\*(Aq\*(Aq); \& say "$stream"; \& \& # Use the alternative constructor \& use Mojo::ByteStream qw(b); \& my $stream = b(\*(Aqfoobarbaz\*(Aq)\->b64_encode(\*(Aq\*(Aq)\->say; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::ByteStream is a scalar-based container for bytestreams that provides a more friendly \s-1API\s0 for many of the functions in Mojo::Util. .PP .Vb 3 \& # Access scalar directly to manipulate bytestream \& my $stream = Mojo::ByteStream\->new(\*(Aqfoo\*(Aq); \& $$stream .= \*(Aqbar\*(Aq; .Ve .SH "FUNCTIONS" .IX Header "FUNCTIONS" Mojo::ByteStream implements the following functions, which can be imported individually. .SS "b" .IX Subsection "b" .Vb 1 \& my $stream = b(\*(Aqtest123\*(Aq); .Ve .PP Construct a new scalar-based Mojo::ByteStream object. .SH "METHODS" .IX Header "METHODS" Mojo::ByteStream implements the following methods. .SS "b64_decode" .IX Subsection "b64_decode" .Vb 1 \& $stream = $stream\->b64_decode; .Ve .PP Base64 decode bytestream with \*(L"b64_decode\*(R" in Mojo::Util. .SS "b64_encode" .IX Subsection "b64_encode" .Vb 2 \& $stream = $stream\->b64_encode; \& $stream = $stream\->b64_encode("\en"); .Ve .PP Base64 encode bytestream with \*(L"b64_encode\*(R" in Mojo::Util. .PP .Vb 2 \& # "Zm9vIGJhciBiYXo=" \& b(\*(Aqfoo bar baz\*(Aq)\->b64_encode(\*(Aq\*(Aq); .Ve .SS "camelize" .IX Subsection "camelize" .Vb 1 \& $stream = $stream\->camelize; .Ve .PP Camelize bytestream with \*(L"camelize\*(R" in Mojo::Util. .SS "clone" .IX Subsection "clone" .Vb 1 \& my $stream2 = $stream\->clone; .Ve .PP Return a new Mojo::ByteStream object cloned from this bytestream. .SS "decamelize" .IX Subsection "decamelize" .Vb 1 \& $stream = $stream\->decamelize; .Ve .PP Decamelize bytestream with \*(L"decamelize\*(R" in Mojo::Util. .SS "decode" .IX Subsection "decode" .Vb 2 \& $stream = $stream\->decode; \& $stream = $stream\->decode(\*(Aqiso\-8859\-1\*(Aq); .Ve .PP Decode bytestream with \*(L"decode\*(R" in Mojo::Util, defaults to using \f(CW\*(C`UTF\-8\*(C'\fR. .PP .Vb 2 \& # "♥" \& b(\*(Aq%E2%99%A5\*(Aq)\->url_unescape\->decode; .Ve .SS "encode" .IX Subsection "encode" .Vb 2 \& $stream = $stream\->encode; \& $stream = $stream\->encode(\*(Aqiso\-8859\-1\*(Aq); .Ve .PP Encode bytestream with \*(L"encode\*(R" in Mojo::Util, defaults to using \f(CW\*(C`UTF\-8\*(C'\fR. .PP .Vb 2 \& # "%E2%99%A5" \& b(\*(Aq♥\*(Aq)\->encode\->url_escape; .Ve .SS "gunzip" .IX Subsection "gunzip" .Vb 1 \& $stream = $stream\->gunzip; .Ve .PP Uncompress bytestream with \*(L"gunzip\*(R" in Mojo::Util. .SS "gzip" .IX Subsection "gzip" .Vb 1 \& stream = $stream\->gzip; .Ve .PP Compress bytestream with \*(L"gzip\*(R" in Mojo::Util. .SS "hmac_sha1_sum" .IX Subsection "hmac_sha1_sum" .Vb 1 \& $stream = $stream\->hmac_sha1_sum(\*(Aqpassw0rd\*(Aq); .Ve .PP Generate \s-1HMAC\-SHA1\s0 checksum for bytestream with \*(L"hmac_sha1_sum\*(R" in Mojo::Util. .PP .Vb 2 \& # "7fbdc89263974a89210ea71f171c77d3f8c21471" \& b(\*(Aqfoo bar baz\*(Aq)\->hmac_sha1_sum(\*(Aqsecr3t\*(Aq); .Ve .SS "html_unescape" .IX Subsection "html_unescape" .Vb 1 \& $stream = $stream\->html_unescape; .Ve .PP Unescape all \s-1HTML\s0 entities in bytestream with \*(L"html_unescape\*(R" in Mojo::Util. .PP .Vb 2 \& # "%3Chtml%3E" \& b(\*(Aq<html>\*(Aq)\->html_unescape\->url_escape; .Ve .SS "humanize_bytes" .IX Subsection "humanize_bytes" .Vb 1 \& $stream = $stream\->humanize_bytes; .Ve .PP Turn number of bytes into a simplified human readable format for bytestream with \*(L"humanize_bytes\*(R" in Mojo::Util. .SS "md5_bytes" .IX Subsection "md5_bytes" .Vb 1 \& $stream = $stream\->md5_bytes; .Ve .PP Generate binary \s-1MD5\s0 checksum for bytestream with \*(L"md5_bytes\*(R" in Mojo::Util. .SS "md5_sum" .IX Subsection "md5_sum" .Vb 1 \& $stream = $stream\->md5_sum; .Ve .PP Generate \s-1MD5\s0 checksum for bytestream with \*(L"md5_sum\*(R" in Mojo::Util. .SS "new" .IX Subsection "new" .Vb 1 \& my $stream = Mojo::ByteStream\->new(\*(Aqtest123\*(Aq); .Ve .PP Construct a new scalar-based Mojo::ByteStream object. .SS "punycode_decode" .IX Subsection "punycode_decode" .Vb 1 \& $stream = $stream\->punycode_decode; .Ve .PP Punycode decode bytestream with \*(L"punycode_decode\*(R" in Mojo::Util. .SS "punycode_encode" .IX Subsection "punycode_encode" .Vb 1 \& $stream = $stream\->punycode_encode; .Ve .PP Punycode encode bytestream with \*(L"punycode_encode\*(R" in Mojo::Util. .SS "quote" .IX Subsection "quote" .Vb 1 \& $stream = $stream\->quote; .Ve .PP Quote bytestream with \*(L"quote\*(R" in Mojo::Util. .SS "say" .IX Subsection "say" .Vb 2 \& $stream = $stream\->say; \& $stream = $stream\->say(*STDERR); .Ve .PP Print bytestream to handle and append a newline, defaults to using \f(CW\*(C`STDOUT\*(C'\fR. .SS "secure_compare" .IX Subsection "secure_compare" .Vb 1 \& my $bool = $stream\->secure_compare($str); .Ve .PP Compare bytestream with \*(L"secure_compare\*(R" in Mojo::Util. .SS "sha1_bytes" .IX Subsection "sha1_bytes" .Vb 1 \& $stream = $stream\->sha1_bytes; .Ve .PP Generate binary \s-1SHA1\s0 checksum for bytestream with \*(L"sha1_bytes\*(R" in Mojo::Util. .SS "sha1_sum" .IX Subsection "sha1_sum" .Vb 1 \& $stream = $stream\->sha1_sum; .Ve .PP Generate \s-1SHA1\s0 checksum for bytestream with \*(L"sha1_sum\*(R" in Mojo::Util. .SS "size" .IX Subsection "size" .Vb 1 \& my $size = $stream\->size; .Ve .PP Size of bytestream. .SS "slugify" .IX Subsection "slugify" .Vb 2 \& $stream = $stream\->slugify; \& $stream = $stream\->slugify($bool); .Ve .PP Generate \s-1URL\s0 slug for bytestream with \*(L"slugify\*(R" in Mojo::Util. .SS "split" .IX Subsection "split" .Vb 2 \& my $collection = $stream\->split(\*(Aq,\*(Aq); \& my $collection = $stream\->split(\*(Aq,\*(Aq, \-1); .Ve .PP Turn bytestream into Mojo::Collection object containing Mojo::ByteStream objects. .PP .Vb 2 \& # "One,Two,Three" \& b("one,two,three")\->split(\*(Aq,\*(Aq)\->map(\*(Aqcamelize\*(Aq)\->join(\*(Aq,\*(Aq); \& \& # "One,Two,Three,,," \& b("one,two,three,,,")\->split(\*(Aq,\*(Aq, \-1)\->map(\*(Aqcamelize\*(Aq)\->join(\*(Aq,\*(Aq); .Ve .SS "tap" .IX Subsection "tap" .Vb 1 \& $stream = $stream\->tap(sub {...}); .Ve .PP Alias for \*(L"tap\*(R" in Mojo::Base. .SS "term_escape" .IX Subsection "term_escape" .Vb 1 \& $stream = $stream\->term_escape; .Ve .PP Escape \s-1POSIX\s0 control characters in bytestream with \*(L"term_escape\*(R" in Mojo::Util. .PP .Vb 2 \& # Print binary checksum to terminal \& b(\*(Aqfoo\*(Aq)\->sha1_bytes\->term_escape\->say; .Ve .SS "to_string" .IX Subsection "to_string" .Vb 1 \& my $str = $stream\->to_string; .Ve .PP Stringify bytestream. .SS "trim" .IX Subsection "trim" .Vb 1 \& $stream = $stream\->trim; .Ve .PP Trim whitespace characters from both ends of bytestream with \*(L"trim\*(R" in Mojo::Util. .SS "unindent" .IX Subsection "unindent" .Vb 1 \& $stream = $stream\->unindent; .Ve .PP Unindent bytestream with \*(L"unindent\*(R" in Mojo::Util. .SS "unquote" .IX Subsection "unquote" .Vb 1 \& $stream = $stream\->unquote; .Ve .PP Unquote bytestream with \*(L"unquote\*(R" in Mojo::Util. .SS "url_escape" .IX Subsection "url_escape" .Vb 2 \& $stream = $stream\->url_escape; \& $stream = $stream\->url_escape(\*(Aq^A\-Za\-z0\-9\e\-._~\*(Aq); .Ve .PP Percent encode all unsafe characters in bytestream with \*(L"url_escape\*(R" in Mojo::Util. .PP .Vb 2 \& # "%E2%98%83" \& b(\*(Aq☃\*(Aq)\->encode\->url_escape; .Ve .SS "url_unescape" .IX Subsection "url_unescape" .Vb 1 \& $stream = $stream\->url_unescape; .Ve .PP Decode percent encoded characters in bytestream with \*(L"url_unescape\*(R" in Mojo::Util. .PP .Vb 2 \& # "<html>" \& b(\*(Aq%3Chtml%3E\*(Aq)\->url_unescape\->xml_escape; .Ve .SS "with_roles" .IX Subsection "with_roles" .Vb 3 \& my $new_class = Mojo::ByteStream\->with_roles(\*(AqMojo::ByteStream::Role::One\*(Aq); \& my $new_class = Mojo::ByteStream\->with_roles(\*(Aq+One\*(Aq, \*(Aq+Two\*(Aq); \& $stream = $stream\->with_roles(\*(Aq+One\*(Aq, \*(Aq+Two\*(Aq); .Ve .PP Alias for \*(L"with_roles\*(R" in Mojo::Base. .SS "xml_escape" .IX Subsection "xml_escape" .Vb 1 \& $stream = $stream\->xml_escape; .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 bytestream with \*(L"xml_escape\*(R" in Mojo::Util. .SS "xor_encode" .IX Subsection "xor_encode" .Vb 1 \& $stream = $stream\->xor_encode($key); .Ve .PP \&\s-1XOR\s0 encode bytestream with \*(L"xor_encode\*(R" in Mojo::Util. .PP .Vb 2 \& # "%04%0E%15B%03%1B%10" \& b(\*(Aqfoo bar\*(Aq)\->xor_encode(\*(Aqbaz\*(Aq)\->url_escape; .Ve .SH "OPERATORS" .IX Header "OPERATORS" Mojo::ByteStream overloads the following operators. .SS "bool" .IX Subsection "bool" .Vb 1 \& my $bool = !!$bytestream; .Ve .PP Always true. .SS "stringify" .IX Subsection "stringify" .Vb 1 \& my $str = "$bytestream"; .Ve .PP Alias for \*(L"to_string\*(R". .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .