Badger...estamp(3pm)

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

✨ Badger::Codec::Timestamp πŸ’–

okay bestie, so this one lives in the Badger::Codec::Timestamp zone β€” it's a Perl module (a 3pm page, iykyk) and its whole thing is encode/decode a timestamp via Badger::Timestamp. that's it. that's the vibe. πŸŽ€


🌸 SYNOPSIS 🌸

use Badger::Codec::Timestamp;
use Badger::Timestamp 'Now';

my $codec   = Badger::Codec::Timestamp->new();
my $encoded = $codec->encode(Now);
my $decoded = $codec->decode($encoded);

πŸ¦‹ DESCRIPTION πŸ¦‹

so this module is a subclass of Badger::Codec, and it does encoding and decoding of timestamps using the Badger::Timestamp module. it is, and I say this with love, trivially simple β€” like, it literally exists only to keep a consistent API with all the other Badger::Codec modules. no cap. ✨

the way it usually shows up is as a codec for reading and writing timestamps to and from a file, through the Badger::Filesystem modules. she's a supporting character, but she's serving. πŸ’…

use Badger::Filesystem 'File';
use Badger::Timestamp 'Now';

my $stamp = Now;                     # current data/time
my $file  = File(
    'example.ts',                   # filename
    { codec => 'timestamp' }        # specify timestamp codec
);

# write timestamp to file
$file->data($stamp);

# read timestamp from file
$stamp = $file->data;

πŸ‘‘ METHODS πŸ‘‘

πŸ“ encode($timestamp)

encodes the timestamp you hand her as an argument. that argument can be a Badger::Timestamp object, or any of the constructor parameters that Badger::Timestamp accepts. flexible queen. πŸ’œ

the example below shows how it works in principle β€” but ngl, it's also completely pointless in practice πŸ™ˆ. it's sufficient to simply call Now->timestamp to serialise a Badger::Timestamp to text, no codec module needed at all. in fact, that's literally all the encode() method does behind the scenes. the audacity. the simplicity. we stan. 😭

use Badger::Timestamp 'Now';
$encoded = Badger::Codec::Timestamp->encode(Now);

🌈 decode($data)

decodes the encoded timestamp you pass as the first argument. returns a Badger::Timestamp object. that's the whole method bestie, she's lowkey iconic for how little she does. ⭐


πŸ’– AUTHOR πŸ’–

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


Copyright (C) 2012 Andy Wardley. All rights reserved.


πŸ”₯ SEE ALSO πŸ”₯

  • Badger::Codecs
  • Badger::Codec
  • Badger::Timestamp

perl v5.36.0 🫢 2023-08-28 β€” mwah, that's a wrap bestie, go serialise some timestamps πŸ’…βœ¨

πŸ“¦ where this page comes from