Debian Codegraph @

README

raw
1 NAME
2
3 Object::Pad::FieldAttr::Isa - apply class type constraints to
4 Object::Pad fields
5
6 SYNOPSIS
7
8 use Object::Pad;
9 use Object::Pad::FieldAttr::Isa;
10
11 class ListNode {
12 field $next :param :reader :writer :Isa(ListNode) = undef;
13 }
14
15 my $first = ListNode->new();
16 my $second = ListNode->new(next => $first);
17
18 # This will fail
19 my $third = ListNode->new(next => "something else");
20
21 # This will fail
22 $second->set_next("another thing");
23
24 DESCRIPTION
25
26 This module provides a third-party field attribute for
27 Object::Pad-based classes, which declares that values assigned to the
28 field must conform to a given object type.
29
30 WARNING The ability for Object::Pad to take third-party field
31 attributes is still new and highly experimental, and subject to much
32 API change in future. As a result, this module should be considered
33 equally experimental.
34
35 FIELD ATTRIBUTES
36
37 :Isa
38
39 field $name :Isa(CLASSNAME) ...;
40
41 Declares that any value assigned to the field must be an object
42 reference, and must be derived from the named class. Attempts to assign
43 a non-conforming value, such as a non-reference, or reference to a
44 class not derived from that named, will throw an exception, and the
45 field value will not be modified.
46
47 This type constraint is applied whenever the field itself is assigned
48 to, whether that is from :param initialisation, invoking a :writer or
49 :mutator accessor, or direct assignment into the field variable by
50 method code within the class.
51
52 AUTHOR
53
54 Paul Evans <[email protected]>
55