Class:...::About(3pm)

πŸ“¦
version 1.14 Β· 2 versions
  • 1.14 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.14 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Class::InsideOut::Manual::About πŸ’–

okay bestie, welcome to Class::InsideOut::Manual::About β€” your user-contributed Perl documentation girlie (section 3pm, she's official-ish but make it cute). This is the guide to this whole technique and to all the other implementations of it out there in the wild. Pull up a chair 🫢


✨ VERSION ✨

version 1.14 β€” that's the one, no cap. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So this manual gives you the whole overview of the inside-out technique and how it shows up inside Class::InsideOut and its friends. It also hands you a whole reading list for further study, because we're studious AND iconic. πŸ“šβœ¨

πŸŽ€ Inside-out object basics πŸŽ€

The vibe: inside-out objects use the blessed reference as an index into lexical data structures that hold the object's properties β€” instead of using the blessed reference itself as a data structure. Two totally different energies, same object:

$self->{ name }        = "Larry"; # classic, hash-based object
$name{ refaddr $self } = "Larry"; # inside-out

And the inside-out approach is giving three major benefits:

  • Enforced encapsulation: object properties cannot be accessed directly from outside the lexical scope that declared them. locked down, no gatecrashers πŸ”’
  • Making the property name part of a lexical variable rather than a hash-key means that typos in the name will be caught as compile-time errors (if using strict). your typos get caught early, bestie, we love a system that yells at you before runtime πŸ’€
  • If the memory address of the blessed reference is used as the index, the reference can be of any type. flexible queen 🌈

But here's the tea: in exchange for these benefits, implementing inside-out objects robustly can be quite complex. And that's the whole point β€” Class::InsideOut manages that complexity for you. 😌

🌸 Philosophy of Class::InsideOut 🌸

Class::InsideOut gives you a set of tools for building safe inside-out classes with maximum flexibility. Periodt.

It aims to offer minimal restrictions beyond those necessary for robustness of the inside-out technique. All capabilities necessary for robustness should be automatic. Anything that can be optional should be. And the design should not introduce new restrictions unrelated to inside-out objects β€” no attributes and no CHECK blocks that cause problems for mod_perl, and no source filters for syntactic sugar. we're not doing that to you πŸ™ˆ

As a result, only a few things are mandatory:

  • Properties must be based on hashes and declared via property
  • Property hashes must be keyed on the Scalar::Util::refaddr
  • register must be called on all new objects

Everything else β€” constructors, initializers, class inheritance management β€” is left to you (though a very simple constructor is available as a convenience, bestie, we got you). This does require some additional work, but it maximizes freedom. Class::InsideOut is intended to be a base class providing only fundamental features. Subclasses of Class::InsideOut could be written that build upon it to provide particular styles of constructor, destructor and inheritance support. DIY but make it safe. πŸ› οΈπŸ’–

πŸ‘‘ Other modules on CPAN πŸ‘‘

  • Object::InsideOut β€” This is perhaps the most full-featured, robust implementation of inside-out objects currently on CPAN. It is highly recommended if a more full-featured inside-out object builder is needed. Its array-based mode is faster than hash-based implementations, but black-box inheritance is handled via delegation, which imposes certain limitations. absolute main character energy πŸ”₯
  • Class::Std β€” Despite the name, this does not reflect currently known best practices for inside-out objects. Does not provide thread-safety with CLONE and doesn't support black-box inheritance. Has a robust inheritance/initialization system. name is a lie, the inheritance system is the good part πŸ’€
  • Class::BuildMethods β€” Generates accessors with encapsulated storage using a flyweight inside-out variant. Lexicals properties are hidden; accessors must be used everywhere. Not thread-safe. 🚫🧡
  • Lexical::Attributes β€” The original inside-out implementation, but missing some key features like thread-safety. Also, uses source filters to provide Perl-6-like object syntax. Not thread-safe. the OG but she has baggage 😭
  • Class::MakeMethods::Templates::InsideOut β€” Not a very robust implementation. Not thread-safe. Not overloading-safe. Has a steep learning curve for the Class::MakeMethods system. πŸͺ¨πŸ“ˆ
  • Object::LocalVars β€” My own original thought experiment with 'outside-in' objects and local variable aliasing. Not safe for any production use and offers very weak encapsulation. a cute little experiment, do NOT ship it 🫣

πŸ“š References for further study πŸ“š

Much of the Perl community discussion of inside-out objects has taken place on Perlmonks (http://perlmonks.org). My scratchpad there has a fairly comprehensive list of articles (http://perlmonks.org/index.pl?node_id=360998). Some of the more informative articles include:


πŸ”₯ SEE ALSO πŸ”₯

  • Class::InsideOut
  • Class::InsideOut::Manual::Advanced

πŸ’œ AUTHOR πŸ’œ

David Golden <dagolden@cpan.org> β€” shoutout to the author, we stan 🫢✨


This software is Copyright (c) 2006 by David A. Golden.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004

and that's the whole page, bestie!! this was rendered with perl v5.36.0 and dated 2022-12-12 β€” so like, remember the vintage, she's a classic πŸŽ€πŸ’– go forth and build safe inside-out objects, ily, bye!! πŸ’…πŸ¦‹