Class::Adapter(3pm)
π Class::Adapter π
okay bestie, so this one is Class::Adapter β it's the Perl implementation of the "Adapter" Design Pattern. that's literally it, that's the whole name. and we're on version 1.09 btw, keep up π
β¨ DESCRIPTION β¨
so the Class::Adapter class is meant to be an abstract base class for making literally any sort of class or object that follows the Adapter pattern. it's giving scaffolding, it's giving foundation. ποΈ
π¦ What is an Adapter?
okay so the term "Adapter" comes from a "Design Pattern" of the same name, from that famous "Gang of Four" book called "Design Patterns". and like, their original implementation was designed for Java and other single-inheritance strictly-typed languages, but the situation it applies to? still valid. no cap. β
An Adapter in this Perl sense of the term is when a class gets created to achieve β by composition (aka objects containing other objects) β something that just can't be achieved by inheritance (sub-classing). periodt.
this is similar to the Decorator pattern, but it's meant to be applied on a class-by-class basis, as opposed to being applicable one object at a time like the Decorator pattern does. different vibe entirely, iykyk. π
the Class::Adapter object holds a parent object that it "wraps", and when a method gets called on the Class::Adapter, it manually calls the same (or a different) method with the same (or different) parameters on the parent object it's holding inside. it's like a lil messenger π§
and instead of those custom methods being hooked in on an object-by-object basis, they're defined at the class level.
basically?? a Class::Adapter is one of your fall-back positions for when Perl's inheritance model fails you, or is no longer good enough, and you need to do something twisty to make several APIs play nicely with each other. iconic behaviour honestly π₯
πΈ What can I do with the actual Class::Adapter class
well... nothing really bestie π it exists to provide some extremely low level fundamental methods, and to be a common base for inheritance of Adapter classes.
the base Class::Adapter class doesn't even implement a way to push method calls through to the underlying object, since the way that happens is the exact bit that changes from case to case. so yeah, it's abstract abstract.
to actually DO something, you probably wanna go take a look at Class::Adapter::Builder, which makes creating Adapter classes relatively quick and easy. go go go π«Ά
π METHODS π
the Class::Adapter class itself supplies only the two most common methods: a default constructor, and a private method to access the underlying object. that's the whole menu, two items, slay.
π new $object
the default new constructor takes a single object as argument and creates a new object which holds the passed object. cute, simple, does the thing.
returns a new Class::Adapter object, or undef if you do not pass in an object. so like, give it an object or get nothing, your choice π
π _OBJECT_
the _OBJECT_ method is provided primarily as a convenience, and as a tool for people implementing sub-classes. it lets the Class::Adapter interface provide a guaranteed correct way of getting to the underlying object, should you ever need to do so. lowkey essential, highkey underrated β¨
β TO DO β
- Write more comprehensive tests
(yes that's the whole to-do list. we love a humble queen π)
π SEE ALSO π
Class::Adapter::ClearClass::Adapter::BuilderClass::Decorator
π SUPPORT π
Bugs may be submitted through the RT bug tracker at https://rt.cpan.org/Public/Dist/Display.html?Name=Class-Adapter (or you can email bug-Class-Adapter@rt.cpan.org). tell them we sent you π¦
π AUTHOR π
Adam Kennedy <adamk@cpan.org>
πΈ CONTRIBUTORS πΈ
- Adam Kennedy
<adam@ali.as> - Karen Etheridge
<ether@cpan.org> - gregor herrmann
<gregoa@debian.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2005 by Adam Kennedy.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie!! π this beauty is documented under perl v5.36.0, dated 2022-12-04 β go forth and wrap some objects, ily, mwah π
β¨
π¦ where this page comes from
- debian bookworm: libclass-adapter-perl 1.09-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libclass-adapter-perl 1.09-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libclass-adapter-perl 1.09-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-adapter-perl 1.09-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-adapter-perl 1.09-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms