Badger::Codec(3pm)

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

πŸ’– Badger::Codec β€” the perl manpage, but make it cute πŸ’–

okay so. this is Badger::Codec, from the User Contributed Perl Documentation section (that's the 3pm part, iykyk), and it's literally the base class for encoding and decoding data. bestie, we're building infrastructure here. let's go. ✨


✨ NAME ✨

Badger::Codec β€” the base class for encoding/decoding data πŸŽ€


🌸 SYNOPSIS 🌸

# creating a Badger::Codec subclass
package My::Codec;
use base 'Badger::Codec';

sub encode {
    my ($self, $data) = @_;
    # do something
    return $encoded_data;
}

sub decode {
    my ($self, $encoded_data) = @_;
    # do something
    return $decoded_data;
}

# using the subclass:
use My::Codec;

my $codec   = My::Codec->new();
my $encoded = $codec->encode($some_data);
my $decoded = $codec->decode($encoded);

πŸ¦‹ INTRODUCTION πŸ¦‹

So this doc? It's about the inner workings of codec modules. Like, the backstage tour. 🫢 You should only need to read this if you're out here writing your own codec subclass, fr fr.

If you just want a general intro to codecs + examples of how to actually use them, go read Badger::Codecs instead. that's the one you want. πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

This module implements a base class codec module for encoding and decoding data to and from different formats. the vibe: it's a base class, so it must be subclassed to actually give you useful implementations of the encode() and decode() methods. on its own? it's giving template. it's giving scaffolding. πŸ’€

In most, if not all cases, subclasses will simply delegate to subroutines provided by other modules. iconic behaviour honestly. for example, the Badger::Codec::Storable module delegates to the freeze() and thaw() methods provided by the Storable module. no cap. ❄️


πŸ”₯ METHODS πŸ”₯

🌈 encode($data)

Method for encoding data. This must be redefined in subclassed modules. like, it's not optional bestie, the base class is not gonna do it for you. 🚨

🌈 decode($data)

Method for decoding data. This must be redefined in subclassed modules. same energy, same rule. don't forget it. πŸ™ˆ

🌈 encoder()

Returns a reference to a subroutine which performs the encoding operation. a lil sub ref. a lil guy. πŸŽ€

🌈 decoder()

Returns a reference to a subroutine which performs the decoding operation. its counterpart. its bestie. 🫢


πŸ‘‘ AUTHOR πŸ‘‘

Andy Wardley <http://wardley.org/> β€” absolute icon, we stan. ✨


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

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, open source, periodt. πŸŽ€


and that's the whole page bestie!! 🌸 one last lil sign-off: this was perl v5.36.0, dated 2023-08-28. mwah πŸ’‹ go write that subclass. you got this. πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from