Badger...:Encode(3pm)

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

✨ Badger::Codec::Encode ✨

okay bestie so this is a page from the User Contributed Perl Documentation for Badger::Codec::Encode β€” and it's about to be your new fave little wrapper, fr fr πŸ’–


🌸 NAME 🌸

Badger::Codec::Encode β€” it's a codec wrapper around Encode. that's it, that's the whole vibe. tiny but mighty πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

use Badger::Codec::Encode;

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

see how clean that is?? obsessed 😭✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so this module is a subclass of Badger::Codec and it's basically the thinnest little wrapper around the Encode module. like, it's barely doing anything on its own, and honestly? iconic. it exists purely so it can have a consistent API with all the other Badger::Codec modules, and to make codec chaining happen. team player energy πŸ‘‘

you'd normally use a codec through the Badger::Codecs module, like this:

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

my $encoding = 'UTF-8';
my $uncoded  = "...some UTF-8 data...";
my $encoded  = encode($encoding, $uncoded);
my $decoded  = decode($encoding, $encoded)

and bestie, that is literally identical to just using the Encode module directly:

use Encode;     # also exports encode()/decode()

plus, a Badger::Codec::Encode object will be available through the codec() subroutine:

my $encoded  = codec->encode($encoding, $uncoded);
my $decoded  = codec->decode($encoding, $encoded)

no cap, that's the whole thing 🫢


πŸ’œ METHODS πŸ’œ

🌈 encode($encoding, $data)

the encoding method πŸ’– it just forwards all its arguments straight to the Encode encode() method. first argument = the encoding, second argument = the data you wanna encode. slay.

$encoded = Badger::Codec::Encode->encode( utf8 => $data );

πŸ“ decode($encoding, $data)

the decoding method πŸ’« and yeah, same deal β€” it forwards all arguments to the Encode decode() method. first argument is the encoding, second is the data to decode. periodt.

$decoded = Badger::Codec::Encode->decode( utf8 => $encoded );

🧚 encoder()

this one returns a reference to the actual real subroutine doing all the encoding work β€” aka the encode() function over in Encode. the main character behind the scenes ✨

πŸ‘‘ decoder()

and this one returns a reference to the actual real subroutine doing all the encoding work β€” aka the decode() method over in Encode. yup, the docs say "encoding work" for the decoder too, and we're not gonna mess with that, we're just gonna report it faithfully πŸ™ˆ


🌟 AUTHOR 🌟

Andy Wardley <http://wardley.org/> β€” ty for your service, king 🫑


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


🌈 SEE ALSO 🌈

  • Encode
  • Badger::Codecs
  • Badger::Codec
  • Badger::Codec::Unicode

okay that's the whole page bestie, go forth and encode responsibly πŸ’…βœ¨

perl v5.36.0 Β· 2023-08-28 β€” mwah, xoxo, and remember: chaining codecs is self-care πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from