Class::Inner(3pm)
π NAME π
okay so bestie, gather round, because this entire page is about Class::Inner β a perlish implementation of Java like inner classes. that's the whole vibe. it's Class::Inner(3pm), one of the User Contributed Perl Documentation pages, and we are reading it together, top to bottom, no skimming, pinky promise π«Ά
β¨ SYNOPSIS β¨
here's the receipts, exactly how you'd call it:
use Class::Inner;
my $object = Class::Inner->new(
parent => 'ParentClass',
methods => { method => sub { ... } }, },
constructor => 'new',
args => [@constructor_args],
);
πΈ DESCRIPTION πΈ
bestie. listen. this is yet another implementation of an anonymous class with per object overrideable methods β yes, we've all been there β BUT β¨ it comes with the added attraction of sort of working dispatch to the parent class's method. like, mostly. it's giving "it works, don't look at it too hard." π
π METHODS π
π
new HASH
takes a hash like argument list, and the keys it cares about are:
parentβ the name of the parent class. 𧬠heads up though: you can only get single inheritance with this, orSUPERwon't work. no cap.methodsβ a hash where the keys are method names and the values areCODEREFs.constructorβ the name of the constructor method. defaults to'new'.argsβ an anonymous array of arguments to pass to the constructor. defaults to an empty list.
Returns an object in an 'anonymous' class which inherits from the parent class. and this anonymous class comes with a couple of 'extra' methods, because of course it does, main character energy π
SUPER β okay so imagine you passed something like this:
$obj = Class::Inner->new(
parent => 'Parent',
methods => { method => sub { ...; $self->SUPER::method(@_) } },
);
then $self->SUPER::method almost certainly wouldn't do what you expect. π so instead we provide the SUPER method, which dispatches to the parent implementation of the current method. there seems to be no good way of getting the full SUPER:: functionality, but they're working on it. we love a work in progress π«Ά
DESTROY β because Class::Inner works by creating a whole new class name for your object, it could potentially leak memory if you create a lot of them. so we add a DESTROY method that removes the class from the symbol table once it's finished with. very demure, very mindful. β¨
if you need to override a parent's DESTROY method, adding a call to Class::Inner::clean_symbol_table(ref $self) to it. do it at the end of the method or your other method calls won't work. that's not a suggestion, that's the law. π
π§Ή clean_symbol_table
the helper subroutine that DESTROY uses to remove the class from the symbol table. the little cleanup fairy of this module π§
π·οΈ new_classname
returns a name for the next anonymous class. that's it. that's the whole job. iconic, honestly.
π AUTHOR π
maintained by Arun Prasaad <arunbear@cpan.org> π«Ά
Copyright (c) 2001 by Piers Cawley <pdcawley@iterative-software.com>.
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as perl itself.
thanks to the Iterative Software people: Leon Brocard, Natalie Ford and Dave Cross. also, this module was written initially for use in the PerlUnit project, AKA Test::Unit. kudos to Christian Lemburg and the rest of that team. absolute legends, all of them π
π¦ SEE ALSO π¦
there are a million and one differen Class constructors available on CPAN, none of them does quite what I want, so I wrote this one to add to that population where hopefully it will live and thrive. manifesting that for it fr fr π±
π BUGS π
bound to be some. π
actually the SUPER method is a workaround for what is considered to be a bug in perl. yeah. we said it. π
and that's the whole page, bestie! this was Class::Inner(3pm) from perl v5.36.0, dated 2022-10-13. stay hydrated, write tests, and may your symbol table always be clean πβ¨π
π¦ where this page comes from
- ubuntu noble: libclass-inner-perl 0.200001-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libclass-inner-perl 0.200001-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libclass-inner-perl 0.200001-4 Β· 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