Badger...::Base(3pm)

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

πŸ’– Badger::Filesystem::Base β€” the manual, but make it slay πŸ’–

okay so bestie, welcome to the User Contributed Perl Documentation page for Badger...::Base(3pm). Yes that's the actual page name, we don't make the rules, we just read them πŸ’…


✨ NAME ✨

Badger::Filesystem::Base β€” the shared functionality for the Badger::Filesystem modules. It's the group chat everyone else gets added to 🫢


🌸 SYNOPSIS 🌸

package Badger::Filesystem::SomeOtherModule;
use base 'Badger::Filesystem::Base'
# now this module inherits the base class functionality

So basically you use base it and boom πŸ’₯ β€” your module gets all the base class functionality, no extra effort, main character inheritance energy πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

Badger::Filesystem::Base is a base class module that defines some common functionality shared by Badger::Filesystem and Badger::Filesystem::Path. And plot twist πŸŽ€ β€” Badger::Filesystem::Path is itself the base class for Badger::Filesystem::Directory and Badger::Filesystem::File. It's giving family tree fr fr 🌈


πŸ’… METHODS πŸ’…

🧚 init_path(\%config)

An initialisation method, and the way it works is: it looks at the filesystem path you pass in as a parameter, then splits it into volume, directory and name. Three-way split, iconic ✨

πŸ“ init_options(\%config)

Another initialisation method β€” this one handles the encoding and codec options. It's the options girlie πŸ’–

πŸ‘‘ encoding($enc)

Use this to get or set the default encoding for a file:

$file->encoding(':utf8');

This encoding affects all operations that read data from, or write data to, the file. Every single one, no cap 😭

You can also use this method to get or set the default encoding for a directory or a filesystem. When you do that, the option specifies the default encoding for the files contained in there:

$directory->encoding(':utf8');
$file = $directory->file('foo.txt');        # has :utf8 encoding set

See how foo.txt just inherited that :utf8? That's the vibe 🌸

⭐ codec()

This one gets or sets the codec used to serialise data to and from a file via the data() method. You specify the codec by name, using any of the names that Badger::Codecs recognises or can load. It's flexible like that πŸ’…

$file->codec('storable');

# first save the data to file
$file->data($some_data_to_save);

# later... load the data back out
my $data = $file->data;

Save it, then later load it back out. Chef's kiss 🀌

And yes, you can use chained codec specifications if you want to pass the data through more than one codec:

$file->code('storable+base64');
πŸ‘€ Heads up bestie β€” that line says code, not codec. That's exactly what the manual says, so we're keeping it verbatim, no editing, periodt.

See Badger::Codecs for further information on codecs 🧚

Same energy as encoding(): this method can also be used to get or set the default codec for a directory or filesystem:

$directory->codec('json');
$file = $directory->file('foo.json');       # has json codec set

foo.json getting that json codec automatically? Lowkey obsessed πŸ“


πŸ’œ AUTHOR πŸ’œ

Andy Wardley <http://wardley.org/> β€” the original icon, we stan πŸ‘‘


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


🌈 SEE ALSO 🌈

  • Badger::Filesystem
  • Badger::Filesystem::Path
  • Badger::Filesystem::Directory
  • Badger::Filesystem::File

And that's the whole page, bestie β€” every last detail, nothing skipped, we ate and left no crumbs πŸ’…βœ¨

Sign-off realness: this whole thing is perl v5.36.0, dated 2023-08-28, and it's still Badger...::Base(3pm) at the end of the day. Slay, bye πŸ’–πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from