Object...::Final(3pm)
πΈ NAME πΈ
Okay bestie, so this page is the man page for Object...::Final(3pm) β yes, that's the manual name right there, cute little abbreviation and all β and what it actually documents is "Object::Pad::FieldAttr::Final", which is the module you want when you need your "Object::Pad" fields to go readonly after construction. Periodt. π
β¨ SYNOPSIS β¨
Like, here's the whole vibe in one screen:
use Object::Pad;
use Object::Pad::FieldAttr::Final;
class Rectangle {
field $width :param :reader :Final;
field $height :param :reader :Final;
field $area :reader :Final;
ADJUST {
$area = $width * $height;
}
}
That's it. That's the whole thing. Slay. π
π¦ DESCRIPTION π¦
So this module hands you a third-party field attribute for classes built with Object::Pad. What does that attribute do, bestie? It declares that the field it's glued onto shall be set as readonly the moment the constructor returns β which means literally no further modification of it is allowed. Locked. Sealed. Iconic. π
WARNING π β the ability for Object::Pad to accept third-party field attributes is still new and highly experimental, and it's subject to much API change in the future. So as a result, this module should be considered equally experimental. No cap β things may absolutely shift under you. Don't say nobody warned you. π
π FIELD ATTRIBUTES π
:Final
Usage, exactly as written:
field $name :Final ...;
field $name :Final ... = DEFAULT;
So here's the tea: it declares that the field variable will be set readonly at the end of the constructor β and that happens after any assignments coming from :param declarations or from ADJUST blocks. From that point on, the value can't otherwise be modified by directly writing into the field variable. Bye-bye mutation energy. π
Watch how this plays out:
field $x :Final;
ADJUST { $x = 123; } # this is permitted
method m { $x = 456; } # this will fail
See? The ADJUST block gets to do its little assignment because it happens before the locking. The method trying to write later? Nope. That one will fail. F in the chat. π
Important: this is only a shallow readonly setting, okay? So if the field variable is holding a reference to a data structure, that structure itself stays mutable. The box is locked, not the contents. β¨
field $aref :Final;
ADJUST { $aref = []; }
method more { push @$aref, "another"; } # this is permitted
Pushing onto it? Totally fine, permitted, go off. The field variable itself just can't be reassigned. π
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
And that's the whole page, bestie! π«Ά This was written up from perl v5.42.3, dated 2026-08-22, and it lives in the manual as Object...::Final(3pm). Go forth and freeze your fields. πβ¨
π¦ where this page comes from
- ubuntu stonking: libobject-pad-fieldattr-final-perl 0.06-2build5 Β· 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