Object...tr::Isa(3pm)

πŸ“¦
version 0.05 Β· 5 versions
, in ubuntu stonking

πŸ’– 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 :param initialisation,
  • invoking a :writer or :mutator accessor,
  • 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