| 1 |
NAME |
| 2 |
Badger - Perl Application Programming Toolkit |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use Badger; |
| 6 |
|
| 7 |
# 1) have more fun |
| 8 |
# 2) get the job done quicker |
| 9 |
# 3) make your code skimpier |
| 10 |
# 4) finish work early |
| 11 |
# 5) go skateboarding |
| 12 |
# 6) enjoy life |
| 13 |
|
| 14 |
DESCRIPTION |
| 15 |
The Badger toolkit is a collection of Perl modules designed to simplify |
| 16 |
the process of building object-oriented Perl applications. It provides a |
| 17 |
set of foundation classes upon which you can quickly build robust and |
| 18 |
reliable systems that are simple, skimpy and scalable. |
| 19 |
|
| 20 |
Badger was hewn from the living rock of the Template Toolkit. It |
| 21 |
represents all the generic bits of TT that aren't directly related to |
| 22 |
template processing. They're also the same kind of generic modules that |
| 23 |
have appeared in pretty much every non-trivial Perl application I've |
| 24 |
written over the past 10 years or so. So Badger is essentially a |
| 25 |
restrospective generalisation of what I've learnt over that time about |
| 26 |
the right way (or more accurately, some of the less wrong ways) to build |
| 27 |
Perl applications. |
| 28 |
|
| 29 |
Badger is designed to be lightweight, fast, and as simple as it can be |
| 30 |
without being too simple. It offers convenience, convention and |
| 31 |
consistency in an attempt to improve the Kwalitee of your code and make |
| 32 |
it more Skimpy™ (which is my artistic interpretation of what Michael |
| 33 |
Schwern refers to as skimmable code - that is, code that is easy to read |
| 34 |
and also easy to skim over). |
| 35 |
|
| 36 |
Badger isn't just another object system. Although it does include |
| 37 |
functionality to simplify the process of building objects in Perl 5, |
| 38 |
that is really just a consequence of the larger goal. That is, to |
| 39 |
provide a self-contained set of OO modules that work together in a |
| 40 |
harmonious way to implement a basic platform upon which applications |
| 41 |
like TT can easily be built. |
| 42 |
|
| 43 |
If you want a comprehensive, highly extensible, postmodern object system |
| 44 |
then Moose should almost certainly be at the top of your list. The parts |
| 45 |
of Badger that deal with object construction are in some ways similar to |
| 46 |
the functionality provided by Moose, not to mention various other object |
| 47 |
toolkits available from CPAN. However, Badger only goes as far as doing |
| 48 |
what it needs to in terms of object construction in order to get the |
| 49 |
rest of the job done. That is, providing a set of objects that do useful |
| 50 |
things. |
| 51 |
|
| 52 |
Furthermore, the choice between Badger, Moose, or something else isn't |
| 53 |
an either-or decision. There are lots of things that Moose does, that |
| 54 |
Badger doesn't, and vice-versa. If you need a really powerful object |
| 55 |
system then Moose is probably the way forward. But that doesn't mean you |
| 56 |
can't use Badger's file handling tools, codecs, and other useful bits |
| 57 |
and pieces alongside your Moose classes. Metaphorically speaking, Badger |
| 58 |
and Moose are best friends and they play nicely together. Anyone for |
| 59 |
tennis? |
| 60 |
|
| 61 |
CONTENTS |
| 62 |
Let's take a quick frolic through the feature list forest to get an idea |
| 63 |
what Badger is all about. |
| 64 |
|
| 65 |
Foundation classes for OO programming |
| 66 |
Badger includes base classes for creating regular objects |
| 67 |
(Badger::Base), mixin objects (Badger::Mixin), prototypes/singletons |
| 68 |
(Badger::Prototype), factory classes (Badger::Factory) and central |
| 69 |
resource hubs (Badger::Hub). |
| 70 |
|
| 71 |
Class Metaprogramming |
| 72 |
The Badger::Class module employs metaprogramming techniques to |
| 73 |
simplify the process of defining object classes. It provides methods |
| 74 |
to automate many of the annoying trivial tasks required to |
| 75 |
"bootstrap" an object class: specifying base classes, version |
| 76 |
numbers, exportable symbols, defining constants, loading utility |
| 77 |
functions from external modules, creating accessor and mutator |
| 78 |
methods, and so on. There are also methods that simplify the process |
| 79 |
of accessing class data (e.g. package variables) to save all that |
| 80 |
mucking about in symbols tables. Some of these methods will also |
| 81 |
account for inheritance between related classes, making it much |
| 82 |
easier to share default configuration values between related |
| 83 |
classed, for example. |
| 84 |
|
| 85 |
A key feature of Badger::Class is that it does this by a process of |
| 86 |
"hygienic class construction". What this means in practice is that |
| 87 |
your object classes don't get polluted with methods that are only |
| 88 |
used to construct the class (e.g. a method that constructs accessor |
| 89 |
methods). |
| 90 |
|
| 91 |
Badger::Class can itself be subclassed, allowing you to build your |
| 92 |
own metaprogramming modules tailored to your particular needs. |
| 93 |
|
| 94 |
Error handling and debugging |
| 95 |
Base classes and mixin modules provide functionality for both hard |
| 96 |
errors in the form of exception-based error handling and soft |
| 97 |
errors for declining requests (e.g. to fetch a resource that |
| 98 |
doesn't exist) that aren't failures but require special handling. |
| 99 |
Methods for debugging (see Badger::Debug) and raising general |
| 100 |
warnings are also provided. Generic hooks are provided for receiving |
| 101 |
notification of, or implementing custom handling for errors, |
| 102 |
warnings and declines. Running alongside this is a generic message |
| 103 |
formatting system that allow you to define all error/warning/debug |
| 104 |
messages in one place where they can easily be localised (e.g. to a |
| 105 |
different spoken language) or customised (e.g. to generate HTML |
| 106 |
format instead of plain text). |
| 107 |
|
| 108 |
Symbol Exporter |
| 109 |
Badger implements an object oriented version of the Exporter module |
| 110 |
in the form of Badger::Exporter. It works correctly with respect to |
| 111 |
class inheritance (that is, a subclass automatically inherits the |
| 112 |
exportable symbols from its base classes) and provides a number of |
| 113 |
additional features to simplify the process of defining exportable |
| 114 |
symbols and adding custom import hooks. |
| 115 |
|
| 116 |
Standard utilities and constants. |
| 117 |
The Badger::Utils module provides a number of simple utility |
| 118 |
functions. It also acts as a delegate to various other standard |
| 119 |
utility modules (Scalar::Util, List::Util, List::MoreUtils, |
| 120 |
Hash::Util and Digest::MD5). Badger::Constants defines various |
| 121 |
constants used by the Badger modules and also of general use. Both |
| 122 |
these modules are designed to be subclassed so that you can create |
| 123 |
your own collections of utility functions, constants, and so on. |
| 124 |
|
| 125 |
Filesystem modules |
| 126 |
The Badger::Filesystem module and friends provide an object-oriented |
| 127 |
interface to a filesystem. Files and directories are represented as |
| 128 |
Badger::Filesystem::File and Badger::Filesystem::Directory objects |
| 129 |
respectively. As well as being useful for general filesystem |
| 130 |
manipulation (in this respect, they are very much like the |
| 131 |
Path::Class modules), the same modules can also be used to represent |
| 132 |
virtual filesystems via the Badger::Filesystem::Virtual module. This |
| 133 |
allows you to "mount" a virtual file system under a particular |
| 134 |
directory (useful when you're dealing with web sites to map page |
| 135 |
URLs, e.g. /example/page.html, to the source files, e.g. |
| 136 |
/path/to/example/page.html). You can also create a virtual file |
| 137 |
system that is a composite of several root directories (if you're |
| 138 |
familiar with the Template Toolkit then think of the way the |
| 139 |
"INCLUDE_PATH" works). |
| 140 |
|
| 141 |
Codec modules |
| 142 |
Going hand-in-hand with many basic filesystem operations, the codec |
| 143 |
modules provide a simple object interface for encoding and decoding |
| 144 |
data to and from any particular format. The underlying functionality |
| 145 |
is provided by existing Perl modules (e.g. MIME::Base64, Storable, |
| 146 |
YAML, etc). The codec modules are wrappers that provide a standard |
| 147 |
interface to these various different modules. It provides both |
| 148 |
functional and object oriented interfaces, regardless of how the |
| 149 |
underlying module works. It also provides the relevant hooks that |
| 150 |
allow codec objects to be composed into pipeline sequences. |
| 151 |
|
| 152 |
Free |
| 153 |
Badger is Open Source and "free" in both "free beer" and "free |
| 154 |
speech" senses of the word. It's 100% pure Perl and has no external |
| 155 |
dependencies on any modules that aren't part of the Perl core. |
| 156 |
Badger is the base platform for version 3 of the Template Toolkit |
| 157 |
(coming RSN) and has portability and ease of installation as primary |
| 158 |
goals. Non-core Badger add-on modules can make as much use of CPAN |
| 159 |
as they like (something that is usually to be encouraged) but the |
| 160 |
Badger core will always be dependency-free to keep it |
| 161 |
upload-to-your-ISP friendly. |
| 162 |
|
| 163 |
FURTHER INFORMATION |
| 164 |
See the documentation included with the Badger modules, starting with |
| 165 |
Badger.pm. Or look online: |
| 166 |
|
| 167 |
http://badgerpower.com/ |
| 168 |
|
| 169 |
AUTHOR |
| 170 |
Andy Wardley |
| 171 |
[email protected] |
| 172 |
http://wardley.org/ |
| 173 |
|
| 174 |
COPYRIGHT |
| 175 |
Copyright (C) 1996-2022 Andy Wardley. All Rights Reserved. |
| 176 |
|
| 177 |
This module is free software; you can redistribute it and/or modify it |
| 178 |
under the same terms as Perl itself. |