table of contents
Object::Pad::SlotAttr::Isa(3pm) | User Contributed Perl Documentation | Object::Pad::SlotAttr::Isa(3pm) |
NAME¶
"Object::Pad::SlotAttr::Isa" - apply class type constraints to "Object::Pad" slots
SYNOPSIS¶
use Object::Pad; use Object::Pad::SlotAttr::Isa; class ListNode { has $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");
DESCRIPTION¶
This module provides a third-party slot attribute for Object::Pad-basedclasses, which declares that values assigned to the slot must conform to agiven object type.
WARNING The ability for Object::Pad to take third-party slot attributes is still new and highly experimental, and subject to much API change in future. As a result, this module should be considered equally experimental.
SLOT ATTRIBUTES¶
:Isa¶
has $slot :Isa(CLASSNAME) ...;
Declares that any value assigned to the slot must be an object reference, andmust be derived from the named class. Attempts to assign a non-conformingvalue, such as a non-reference, or reference to a class not derived from thatnamed, will throw an exception, and the slot value will not be modified.
This type constraint is applied whenever the slot itself is assigned to,whether that is from ":param" initialisation, invoking a ":writer" or ":mutator" accessor, or direct assignment into the slot variable by method code within the class.
AUTHOR¶
Paul Evans <leonerd@leonerd.org.uk>
2022-02-07 | perl v5.34.0 |