What Else Does it Do?
Filesystem Layer (
- Wrappers around core
- OO abstraction of paths, files, directories
- Flexible and extensible
- Encode and Decode stuff
- Unicode, MIME::Base64, YAML, JSON, Storable
- Wrappers around existing modules
- Consistent user interfaces (OO or functional)
- Composable units
Thus Spake Andy:
Badger also provides a filesystem layer which acts as a wrapper around Perl's
File::* modules. These modules do the job well enough, but have a
variety of different APIs that can make using them a bit of a minefield. The
Badger filesystem layer provides an OO abstraction of a filesystem, very much
like the most excellent
Path::Class modules. Unfortunately,
doesn't quite provide the kind of flexibility and extensibility that I
needed for TT. I started off with a set of wrapper modules around
Path::Class but eventually migrated to a new implementation using flyweight
objects. Here each file or directory is a simply flyweight object which stores
a path URI and a reference back to a filesystem object. All methods (e.g.
$file->read) are delegated back to the filesystem object (e.g.
$filesystem->read_file($file->uri)). This makes it easier to implement
filesystem extensions, like the kind of virtual filesystem that TT's
INCLUDE_PATH uses to aggregate a number of source directories into a single
virtual directory view.
Going hand-in-hand with file handling are the handy
managed by the
Badger::Codecs factory module. A codec is something that
encodes and decodes data from one format to another. Each of the Badger codec
modules is a thin wrapper around another module (e.g.
MIME::Base64) which provides a consistent API. You can choose to use either
an OO API (e.g.
$codec->decode()) or a functional API
decode()). The codec wrapper Does The Right Thing™ to
map it to whatever the underlying modules does (
to_json(), etc). One of the nice thing that falls out of this is that
all your codecs then have the same API and can be automatically composed
into efficient codec chains that perform several encoding or decoding steps