.\" 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::ByteStream 3pm" .TH Mojo::ByteStream 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::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 \*(Aqb\*(Aq; \& 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 1 \& b(\*(Aqfoo bar baz\*(Aq)\->b64_encode(\*(Aq\*(Aq)\->say; .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 Clone 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 \f(CW\*(C`UTF\-8\*(C'\fR. .PP .Vb 1 \& $stream\->decode(\*(AqUTF\-16LE\*(Aq)\->unquote\->trim\->say; .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 \f(CW\*(C`UTF\-8\*(C'\fR. .PP .Vb 1 \& $stream\->trim\->quote\->encode\->say; .Ve .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 1 \& b(\*(Aqfoo bar baz\*(Aq)\->hmac_sha1_sum(\*(Aqsecr3t\*(Aq)\->quote\->say; .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 1 \& b(\*(Aq<html>\*(Aq)\->html_unescape\->url_escape\->say; .Ve .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 \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. .PP .Vb 1 \& say \*(AqMatch!\*(Aq if b(\*(Aqfoo\*(Aq)\->secure_compare(\*(Aqfoo\*(Aq); .Ve .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 "slurp" .IX Subsection "slurp" .Vb 1 \& $stream = $stream\->slurp; .Ve .PP Read all data at once from file into bytestream with \*(L"slurp\*(R" in Mojo::Util. .PP .Vb 1 \& b(\*(Aq/home/sri/myapp.pl\*(Aq)\->slurp\->split("\en")\->shuffle\->join("\en")\->say; .Ve .SS "spurt" .IX Subsection "spurt" .Vb 1 \& $stream = $stream\->spurt(\*(Aq/home/sri/myapp.pl\*(Aq); .Ve .PP Write all data from bytestream at once to file with \*(L"spurt\*(R" in Mojo::Util. .PP .Vb 1 \& b(\*(Aq/home/sri/foo.txt\*(Aq)\->slurp\->squish\->spurt(\*(Aq/home/sri/bar.txt\*(Aq); .Ve .SS "split" .IX Subsection "split" .Vb 1 \& my $collection = $stream\->split(\*(Aq,\*(Aq); .Ve .PP Turn bytestream into Mojo::Collection object containing Mojo::ByteStream objects. .PP .Vb 1 \& b(\*(Aqa,b,c\*(Aq)\->split(\*(Aq,\*(Aq)\->quote\->join(\*(Aq,\*(Aq)\->say; .Ve .SS "squish" .IX Subsection "squish" .Vb 1 \& $stream = $stream\->squish; .Ve .PP Trim whitespace characters from both ends of bytestream and then change all consecutive groups of whitespace into one space each with \&\*(L"squish\*(R" in Mojo::Util. .SS "tap" .IX Subsection "tap" .Vb 1 \& $stream = $stream\->tap(sub {...}); .Ve .PP Alias for \*(L"tap\*(R" in Mojo::Base. .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 1 \& b(\*(Aqfoo bar baz\*(Aq)\->url_escape\->say; .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 1 \& b(\*(Aq%3Chtml%3E\*(Aq)\->url_unescape\->xml_escape\->say; .Ve .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. .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, .