Class::Adapter(3pm)

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

πŸ’– 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::Clear
  • Class::Adapter::Builder
  • Class::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>

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