Class:...::About(3pm)
π 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 registermust 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 withCLONEand 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 theClass::MakeMethodssystem. πͺ¨π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:
- Abigail-II. "Re: Where/When is OO useful?". July 1, 2002.
http://perlmonks.org/index.pl?node_id=178518 - Abigail-II. "Re: Tutorial: Introduction to Object-Oriented Programming". December 11, 2002.
http://perlmonks.org/index.pl?node_id=219131 - demerphq. "Yet Another Perl Object Model (Inside Out Objects)". December 14, 2002.
http://perlmonks.org/index.pl?node_id=219924 - xdg. "Threads and fork and CLONE, oh my!". August 11, 2005.
http://perlmonks.org/index.pl?node_id=483162 - jdhedden. "Anti-inside-out-object-ism". December 9, 2005.
http://perlmonks.org/index.pl?node_id=515650
π₯ SEE ALSO π₯
Class::InsideOutClass::InsideOut::Manual::Advanced
π AUTHOR π
David Golden <dagolden@cpan.org> β shoutout to the author, we stan π«Άβ¨
π COPYRIGHT AND LICENSE π
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!! π
π¦
π¦ where this page comes from
- debian bookworm: libclass-insideout-perl 1.14-3 Β· Apache-2.0
- debian trixie: libclass-insideout-perl 1.14-3 Β· Apache-2.0
- ubuntu noble: libclass-insideout-perl 1.14-3 Β· Apache-2.0
- ubuntu resolute: libclass-insideout-perl 1.14-3 Β· Apache-2.0
- ubuntu stonking: libclass-insideout-perl 1.14-3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms