.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 2024-05-15 "perl v5.38.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::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 API 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 "b64_decode" 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 "b64_encode" 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 "camelize" 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 "decamelize" 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 "decode" 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 "encode" 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 "gunzip" in Mojo::Util. .SS gzip .IX Subsection "gzip" .Vb 1 \& stream = $stream\->gzip; .Ve .PP Compress bytestream with "gzip" in Mojo::Util. .SS hmac_sha1_sum .IX Subsection "hmac_sha1_sum" .Vb 1 \& $stream = $stream\->hmac_sha1_sum(\*(Aqpassw0rd\*(Aq); .Ve .PP Generate HMAC\-SHA1 checksum for bytestream with "hmac_sha1_sum" 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 HTML entities in bytestream with "html_unescape" 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 "humanize_bytes" in Mojo::Util. .SS md5_bytes .IX Subsection "md5_bytes" .Vb 1 \& $stream = $stream\->md5_bytes; .Ve .PP Generate binary MD5 checksum for bytestream with "md5_bytes" in Mojo::Util. .SS md5_sum .IX Subsection "md5_sum" .Vb 1 \& $stream = $stream\->md5_sum; .Ve .PP Generate MD5 checksum for bytestream with "md5_sum" 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 "punycode_decode" in Mojo::Util. .SS punycode_encode .IX Subsection "punycode_encode" .Vb 1 \& $stream = $stream\->punycode_encode; .Ve .PP Punycode encode bytestream with "punycode_encode" in Mojo::Util. .SS quote .IX Subsection "quote" .Vb 1 \& $stream = $stream\->quote; .Ve .PP Quote bytestream with "quote" 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 "secure_compare" in Mojo::Util. .SS sha1_bytes .IX Subsection "sha1_bytes" .Vb 1 \& $stream = $stream\->sha1_bytes; .Ve .PP Generate binary SHA1 checksum for bytestream with "sha1_bytes" in Mojo::Util. .SS sha1_sum .IX Subsection "sha1_sum" .Vb 1 \& $stream = $stream\->sha1_sum; .Ve .PP Generate SHA1 checksum for bytestream with "sha1_sum" 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 URL slug for bytestream with "slugify" 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 "tap" in Mojo::Base. .SS term_escape .IX Subsection "term_escape" .Vb 1 \& $stream = $stream\->term_escape; .Ve .PP Escape POSIX control characters in bytestream with "term_escape" 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 "trim" in Mojo::Util. .SS unindent .IX Subsection "unindent" .Vb 1 \& $stream = $stream\->unindent; .Ve .PP Unindent bytestream with "unindent" in Mojo::Util. .SS unquote .IX Subsection "unquote" .Vb 1 \& $stream = $stream\->unquote; .Ve .PP Unquote bytestream with "unquote" 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 "url_escape" 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 "url_unescape" 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 "with_roles" 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 "xml_escape" in Mojo::Util. .SS xor_encode .IX Subsection "xor_encode" .Vb 1 \& $stream = $stream\->xor_encode($key); .Ve .PP XOR encode bytestream with "xor_encode" 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 "to_string". .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .