Perl implementation of the "adapter" design pattern
The \*(C`Class::Adapter\*(C' class is intended as an abstract base class for creating any sort of class or object that follows the Adapter pattern.
The term Adapter refers to a \*(L"Design Pattern\*(R" of the same name, from the famous \*(L"Gang of Four\*(R" book \*(L"Design Patterns\*(R". Although their original implementation was designed for Java and similar single-inheritance strictly-typed langauge, the situation for which it applies is still valid.
An Adapter in this Perl sense of the term is when a class is created to achieve by composition (objects containing other object) something that can't be achieved by inheritance (sub-classing).
This is similar to the Decorator pattern, but is intended to be applied on a class-by-class basis, as opposed to being able to be applied one object at a time, as is the case with the Decorator pattern.
The \*(C`Class::Adapter\*(C' object holds a parent object that it \*(L"wraps\*(R", and when a method is called on the \*(C`Class::Adapter\*(C', it manually calls the same (or different) method with the same (or different) parameters on the parent object contained within it.
Instead of these custom methods being hooked in on an object-by-object basis, they are defined at the class level.
Basically, a \*(C`Class::Adapter\*(C' is one of your fall-back positions when Perl's inheritance model fails you, or is no longer good enough, and you need to do something twisty in order to make several APIs play nicely with each other.
Well... nothing really. It exist to provide some extremely low level fundamental methods, and to provide a common base for inheritance of Adapter classes.
The base \*(C`Class::Adapter\*(C' class doesn't even implement a way to push method calls through to the underlying object, since the way in which that happens is the bit that changes from case to case.
To actually \s-1DO\s0 something, you probably want to go take a look at Class::Adapter::Builder, which makes the creation of Adapter classes relatively quick and easy.
The \*(C`Class::Adapter\*(C' class itself supplies only the two most common methods, a default constructor and a private method to access the underlying object. The default \*(C`new\*(C' constructor takes a single object as argument and creates a new object which holds the passed object.
Returns a new \*(C`Class::Adapter\*(C' object, or \*(C`undef\*(C' if you do not pass in an object.
The \*(C`_OBJECT_\*(C' method is provided primarily as a convenience, and a tool for people implementing sub-classes, and allows the \*(C`Class::Adapter\*(C' interface to provide a guarenteed correct way of getting to the underlying object, should you need to do so.
Bugs should be reported via the \s-1CPAN\s0 bug tracker at
<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Class-Adapter>
For other issues, contact the author.
- Write more comprehensive tests
Adam Kennedy <[email protected]>
Class::Adapter::Clear, Class::Adapter::Builder, Class::Decorator
Copyright 2005 - 2010 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the \s-1LICENSE\s0 file included with this module.