Skip to content

Commit

Permalink
better Mojo::ByteStream examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 19, 2015
1 parent f11624e commit c003913
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -124,7 +124,8 @@ Base64 decode bytestream with L<Mojo::Util/"b64_decode">.
Base64 encode bytestream with L<Mojo::Util/"b64_encode">.
b('foo bar baz')->b64_encode('')->say;
# "Zm9vIGJhciBiYXo="
b('foo bar baz')->b64_encode('');
=head2 camelize
Expand All @@ -151,7 +152,8 @@ Decamelize bytestream with L<Mojo::Util/"decamelize">.
Decode bytestream with L<Mojo::Util/"decode">, defaults to using C<UTF-8>.
$stream->decode('UTF-16LE')->unquote->trim->say;
# "♥"
b('%E2%99%A5')->url_unescape->decode;
=head2 encode
Expand All @@ -160,23 +162,26 @@ Decode bytestream with L<Mojo::Util/"decode">, defaults to using C<UTF-8>.
Encode bytestream with L<Mojo::Util/"encode">, defaults to using C<UTF-8>.
$stream->trim->quote->encode->say;
# "%E2%99%A5"
b('♥')->encode->url_escape;
=head2 hmac_sha1_sum
$stream = $stream->hmac_sha1_sum('passw0rd');
Generate HMAC-SHA1 checksum for bytestream with L<Mojo::Util/"hmac_sha1_sum">.
b('foo bar baz')->hmac_sha1_sum('secr3t')->quote->say;
# "7fbdc89263974a89210ea71f171c77d3f8c21471"
b('foo bar baz')->hmac_sha1_sum('secr3t');
=head2 html_unescape
$stream = $stream->html_unescape;
Unescape all HTML entities in bytestream with L<Mojo::Util/"html_unescape">.
b('&lt;html&gt;')->html_unescape->url_escape->say;
# "%3Chtml%3E"
b('&lt;html&gt;')->html_unescape->url_escape;
=head2 md5_bytes
Expand Down Expand Up @@ -227,8 +232,6 @@ Print bytestream to handle and append a newline, defaults to using C<STDOUT>.
Compare bytestream with L<Mojo::Util/"secure_compare">.
say 'Match!' if b('foo')->secure_compare('foo');
=head2 sha1_bytes
$stream = $stream->sha1_bytes;
Expand All @@ -253,6 +256,7 @@ Size of bytestream.
Read all data at once from file into bytestream with L<Mojo::Util/"slurp">.
# Read file and print lines in random order
b('/home/sri/myapp.pl')->slurp->split("\n")->shuffle->join("\n")->say;
=head2 spurt
Expand All @@ -261,6 +265,7 @@ Read all data at once from file into bytestream with L<Mojo::Util/"slurp">.
Write all data from bytestream at once to file with L<Mojo::Util/"spurt">.
# Remove unnecessary whitespace from file
b('/home/sri/foo.txt')->slurp->squish->spurt('/home/sri/bar.txt');
=head2 split
Expand All @@ -270,7 +275,8 @@ Write all data from bytestream at once to file with L<Mojo::Util/"spurt">.
Turn bytestream into L<Mojo::Collection> object containing L<Mojo::ByteStream>
objects.
b('a,b,c')->split(',')->quote->join(',')->say;
# "One,Two,Three"
b("one,two,three")->split(',')->map('camelize')->join(',');
=head2 squish
Expand All @@ -293,6 +299,7 @@ Alias for L<Mojo::Base/"tap">.
Escape POSIX control characters in bytestream with
L<Mojo::Util/"term_escape">.
# Print binary checksum to terminal
b('foo')->sha1_bytes->term_escape->say;
=head2 to_string
Expand Down Expand Up @@ -328,7 +335,8 @@ Unquote bytestream with L<Mojo::Util/"unquote">.
Percent encode all unsafe characters in bytestream with
L<Mojo::Util/"url_escape">.
b('foo bar baz')->url_escape->say;
# "%E2%98%83"
b('☃')->encode->url_escape;
=head2 url_unescape
Expand All @@ -337,7 +345,8 @@ L<Mojo::Util/"url_escape">.
Decode percent encoded characters in bytestream with
L<Mojo::Util/"url_unescape">.
b('%3Chtml%3E')->url_unescape->xml_escape->say;
# "&lt;html&gt;"
b('%3Chtml%3E')->url_unescape->xml_escape;
=head2 xml_escape
Expand All @@ -352,7 +361,8 @@ bytestream with L<Mojo::Util/"xml_escape">.
XOR encode bytestream with L<Mojo::Util/"xor_encode">.
b('foo bar')->xor_encode('baz')->url_escape->say;
# "%04%0E%15B%03%1B%10"
b('foo bar')->xor_encode('baz')->url_escape;
=head1 OPERATORS
Expand Down

0 comments on commit c003913

Please sign in to comment.