class ValueObjAt

Unique identification for value types
class ValueObjAt is ObjAt { }

A subclass of ObjAt that should be used to indicate that a class produces objects that are value types - in other words, that are immutable after they have been initialized.

my %h = a => 42;    # mutable Hash
    say %h.WHICH.raku;  # OUTPUT: «ObjAt.new("Hash|2972851925856")␤»
my $date = Date.new(2025,7,20);  # immutable Date
    say $date.WHICH.raku;            # OUTPUT: «ValueObjAt.new("Date|60876")␤»

If you create a class that should be considered a value type, you should add a WHICH method to that class that returns a ValueObjAt object, for instance:

class YourClass {
        has $.foo;  # note these are not mutable
        has $.bar;
method WHICH() {
            ValueObjAt.new("YourClass|$!foo|$!bar");
        }
    }

Note that it is customary to always start the identifying string with the name of the object, followed by a "|". This to prevent confusion with other classes that may generate similar string values: the name of the class should then be enough of a differentiator to prevent collisions.

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.