Skip to content

Commit 208213b

Browse files
committed
Document ValueObjAt
1 parent 5e73790 commit 208213b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

doc/Type/ObjAt.pod6

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ objects, and identify an object uniquely.
1212
If two objects compare equally via C<===>, their C<.WHICH> methods return
1313
the same ObjAt object.
1414
15+
See also L<ValueObjAt> for value types.
16+
1517
=end pod
1618

1719
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

doc/Type/ValueObjAt.pod6

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

0 commit comments

Comments
 (0)