Object...tr::Isa(3pm)
π Object::Pad::FieldAttr::Isa β bestie edition π
(that's the whole name, Object::Pad::FieldAttr::Isa, living under the 3pm manual, and it does exactly one gorgeous little thing)
π¦ NAME π¦
Object::Pad::FieldAttr::Isa β it slaps class type constraints onto your Object::Pad fields, no cap π
β¨ SYNOPSIS β¨
Ok so picture this, you just want your linked list to only accept actual ListNode objects:
use Object::Pad;
use Object::Pad::FieldAttr::Isa;
class ListNode {
field $next :param :reader :writer :Isa(ListNode) = undef;
}
my $first = ListNode->new();
my $second = ListNode->new(next => $first);
# This will fail
my $third = ListNode->new(next => "something else");
# This will fail
$second->set_next("another thing");
Like. The vibe check is built in. It's giving immaculate type safety π«Ά
πΈ DESCRIPTION πΈ
So here's the tea, bestie: this module hands you a third-party field attribute for Object::Pad-based classes. What does that attribute do? It declares that whatever values get assigned to your field must conform to a given object type. That's it. That's the whole job. And it eats. π
WARNING okay so listen π₯ the ability for Object::Pad to even take third-party field attributes is still super new and highly experimental, and it's subject to so much API change in the future, like genuinely a lot. Which means this module should be considered equally experimental. Use it knowing the ground might shift under you, fr fr π
π FIELD ATTRIBUTES π
π :Isa
field $name :Isa(CLASSNAME) ...;
Okay so what this is saying is: any value assigned to the field must be an object reference, and it must be derived from the named class.
What happens if you try to sneak something in that doesn't conform? Like a non-reference, or a reference to a class that isn't derived from the one you named? It throws an exception. And the field value will not be modified. The old value stays put. Iconic behaviour honestly, it's very "not today" of it π
And the important bit β this type constraint gets applied whenever the field itself is assigned to, whether that's:
- from
:paraminitialisation, - invoking a
:writeror:mutatoraccessor, - or a direct assignment into the field variable by method code inside the class.
All of it. Every path in. No exceptions, except the exception it throws π
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
and that's the whole page bestie, mwah π
signing off with perl v5.42.3, dated 2026-08-22, from Object...tr::Isa(3pm) β go forth and type-constrain your fields, you absolutely ate πβ¨π
π¦ where this page comes from
- ubuntu stonking: libobject-pad-fieldattr-isa-perl 0.05-1build5 Β· 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