Around line 477, it explains that

            our $count;
            method ^count { return $count }
        
        Such a I<metaclass method> is always delegated to the C<HOW>
        object just as methods like C<.does> are, so it's possible to call
        this as C<Dog.count> or C<$dog.count>.

However, around line 1983 it illustrates

        But C<Any> gives you shortcuts to those:
        
            $obj.can("bark")
            $obj.does(Dog)
            $obj.isa(Mammal)

        ...In general, C<Any> will delegate only those metamethods
        that read well when reasoning about an individual object.
        Infrastructural methods like C<.^methods> and C<.^attributes>
        are not delegated, so C<$obj.methods> fails.

That is, metamethods are not automatically delegated by the dispatcher, but rather ordinary methods forward to the metamethod to enable that form of calling.

---

Over and over the document warns that you really shouldn't use the shortcut form. So I'd suggest that the second way is right. If you want a shortcut to be available (if the method reads well when reasoning about an individual object) then write one, too.

Or, why define the ^foo form in the first place? As it explains earlier, any method can be called on the protoobject as long as it doesn't try and access the undefined parts of the instance. So if you want to call $obj.count, then write method count, not method ^count.

You can also have a trait that generates the shortcut method as well, as syntactic sugar. That does not require any new language features.

--John

Reply via email to