=begin pod :kind("Type") :subkind("role") :category("metamodel")

=TITLE role Metamodel::Trusting

=SUBTITLE Metaobject that supports trust relations between types

=for code :preamble<class SuperClass {};>
role Metamodel::Trusting is SuperClass { ... }

I<Warning>: this role is part of the Rakudo implementation, and is not
a part of the language specification.

Normally, code in a class or role can only access its own private methods. If
another type declares that it trusts that first class, then access to private
methods of that second type is possible. C<Metamodel::Trusting> implements
that aspect of the Raku object system.

    class A {
        my class B {
            trusts A;   # that's where Metamodel::Trusting comes in
            method !private_method() {
                say "Private method in B";
            }
        }
        method build-and-poke {
            # call a private method from B
            # disallowed if A doesn't trust B
            B.new()!B::private_method();
        }
    };

    A.build-and-poke;   # Private method in A

=head1 Methods

=head2 method add_trustee

    method add_trustee($type, Mu $trustee)

Trust C<$trustee>.

=for code :preamble<class B {};>
class A {
    BEGIN A.^add_trustee(B);
    # same as 'trusts B';
}

=head2 method trusts

    method trusts($type --> List)

Returns a list of types that the invocant trusts.

    class A { trusts Int; };
    say .^name for A.^trusts;       # Int

=head2 method is_trusted

    method is_trusted($type, $claimant)

Returns 1 if C<$type> trusts C<$claimant>, and 0 otherwise.
Types always trust themselves.

=end pod
