Badger...nicode(3pm)
π 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 π
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
- debian trixie: libbadger-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libbadger-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libbadger-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms