Badger::Codec(3pm)
π 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 π
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
- 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