Badger...nicode(3pm)

πŸ“¦
version 0.16 Β· 4 versions
, in debian trixie, ubuntu noble, ubuntu resolute

πŸ’– Badger::Codec::Unicode β€” encode/decode Unicode πŸ’–

okay so bestie, let me put you onto Badger::Codec::Unicode, a little perl module (a 3pm page, user contributed docs, we love to see it) that handles your Unicode encode/decode sitch. it's giving tiny but mighty. no cap.


✨ SYNOPSIS ✨

use Badger::Codec::Unicode;
my $codec   = Badger::Codec::Unicode->new();
my $uncoded = "...some Unicode data...";
my $encoded = $codec->encode($uncoded);
my $decoded = $codec->decode($encoded);

🌸 DESCRIPTION 🌸

so like, this module is a subclass of Badger::Codec, and honestly? it's a very thin wrapper around the Encode module for encoding and decoding Unicode. that's the whole vibe. thin wrapper, big energy.

a Badger::Codec::Unicode object hands you the encode() and decode() methods for, you guessed it, encoding and decoding Unicode:

use Badger::Codec::Unicode;
my $codec   = Badger::Codec::Unicode->new();
my $uncoded = "...some Unicode data...";
my $encoded = $codec->encode($uncoded);
my $decoded = $codec->decode($encoded);

you can also call encode() and decode() as class methods, no object required. main character behavior:

my $encoded = Badger::Code::Unicode->encode($uncoded);
my $decoded = Badger::Code::Unicode->decode($encoded);

and you can pull a codec in via the Badger::Codecs module too:

use Badger::Codecs
    codec => 'unicode';

that one exports the encode() and decode() subroutines for you:

my $uncoded  = "...some Unicode data...";
my $encoded  = encode($uncoded);
my $decoded  = decode($encoded)

πŸ¦‹ METHODS πŸ¦‹

πŸ’… encode($encoding, $data)

the method for encoding Unicode data. give it two arguments and the first one is the encoding, the second one is the data you wanna encode:

$encoded = $codec->encode( utf8 => $data );

give it just one argument and the encoding defaults to "UTF-8", periodt:

$utf8 = $codec->encode($data);

πŸŽ€ decode($encoding, $data)

the method for decoding Unicode data. two arguments? first is the encoding, second is the data to decode:

$decoded = $codec->decode( utf8 => $encoded );

one argument only? then it goes looking for a Byte Order Mark (BOM) to figure out the encoding itself. and listen β€” if there's no BOM, or the BOM doesn't match a supported Unicode BOM (that's any of "UTF-8", "UTF-32BE" "UTF-32LE", "UTF-16BE" or "UTF-16LE"), then the data will not be decoded as Unicode. like, at all. so don't come crying to me πŸ™ˆ

$decoded = $codec->decode($encoded);    # use BOM to detect encoding

🌈 encoder()

this one returns a subroutine reference you can call to encode Unicode data. internally it calls the encode() method:

my $encoder = $codec->encode;
$encoded = $encoder->($data);

⭐ decoder()

same deal but the other direction: returns a subroutine reference you can call to decode Unicode data. internally it calls the decode() method:

my $decoder = $codec->decode;
$decoded = $decoder->($data);

πŸ‘‘ AUTHOR πŸ‘‘

Andy Wardley <http://wardley.org/>


Copyright (C) 2005-2009 Andy Wardley. All rights reserved.


πŸ”₯ SEE ALSO πŸ”₯

Encode, Badger::Codec::Encode, Badger::Codecs, Badger::Codec.


and that's the whole page bestie, tysm for reading, ily 🫢 β€” this lil doc came to you courtesy of perl v5.36.0, dated 2023-08-28, from the Badger::Codec::Unicode(3pm) page itself πŸ’–βœ¨

πŸ“¦ where this page comes from