File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ objects, and identify an object uniquely.
12
12
If two objects compare equally via C < === > , their C < .WHICH > methods return
13
13
the same ObjAt object.
14
14
15
+ See also L < ValueObjAt > for value types.
16
+
15
17
= end pod
16
18
17
19
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
Original file line number Diff line number Diff line change
1
+ = begin pod
2
+
3
+ = TITLE class ValueObjAt
4
+
5
+ = SUBTITLE Unique identification for value types
6
+
7
+ class ValueObjAt is ObjAt { }
8
+
9
+ A subclass of L < C < ObjAt > |ObjAt> that should be used to indicate that a class
10
+ produces objects that are value types (in other words: are immutable after
11
+ they have been initialized.
12
+
13
+ my %h = a => 42; # mutable Hash
14
+ say %h.WHICH; # ObjAt.new("Hash|1402...1161888")
15
+
16
+ my %m is Map = a => 42; # immutable Map
17
+ say %m.WHICH; # ValueObjAt.new("Map|AAF...09F61F")
18
+
19
+ If you create a class that should be considered a value type, you should add
20
+ a C < WHICH > method to that class that returns a C < ValueObjAt > object, for
21
+ instance:
22
+
23
+ class YourClass {
24
+ has $.foo; # note these are not mutable
25
+ has $.bar;
26
+
27
+ method WHICH() {
28
+ ValueObjAt.new("YourClass|$!foo|$!bar");
29
+ }
30
+ }
31
+
32
+ Note that it is customary to always start the identifying string with the
33
+ name of the object, followed by a "|". This to prevent confusion with other
34
+ classes that may generate similar string values: the name of the class should
35
+ then be enough of a differentiator to prevent collisions.
36
+
37
+ = end pod
38
+
39
+ # vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
You can’t perform that action at this time.
0 commit comments