role Metamodel::Trusting

Metaobject that supports trust relations between types

role Metamodel::Trusting is SuperClass { ... }

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. Metamodel::Trusting implements that aspect of the Perl 6 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 

Methods

method add_trustee

method add_trustee(Metamodel::Trusting:D: $typeMu $trustee)

Trust $trustee.

class A {
    BEGIN A.^add_trustee(B);
    # same as 'trusts B'; 
}

method trusts

method trusts(Metamodel::Trusting:D: $type --> List)

Returns a list of types that the invocant trusts.

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

method is_trusted

method is_trusted(Metamodel::Trusting:D: $type$claimant)

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

Type graph

Type relations for Metamodel::Trusting
perl6-type-graph Metamodel::Trusting Metamodel::Trusting Mu Mu Any Any Any->Mu Metamodel::Naming Metamodel::Naming Metamodel::Documenting Metamodel::Documenting Metamodel::Versioning Metamodel::Versioning Metamodel::Stashing Metamodel::Stashing Metamodel::AttributeContainer Metamodel::AttributeContainer Metamodel::Finalization Metamodel::Finalization Metamodel::MethodContainer Metamodel::MethodContainer Metamodel::PrivateMethodContainer Metamodel::PrivateMethodContainer Metamodel::MultiMethodContainer Metamodel::MultiMethodContainer Metamodel::RoleContainer Metamodel::RoleContainer Metamodel::MultipleInheritance Metamodel::MultipleInheritance Metamodel::DefaultParent Metamodel::DefaultParent Metamodel::C3MRO Metamodel::C3MRO Metamodel::MROBasedMethodDispatch Metamodel::MROBasedMethodDispatch Metamodel::MROBasedTypeChecking Metamodel::MROBasedTypeChecking Metamodel::BUILDPLAN Metamodel::BUILDPLAN Metamodel::Mixins Metamodel::Mixins Metamodel::BoolificationProtocol Metamodel::BoolificationProtocol Metamodel::ClassHOW Metamodel::ClassHOW Metamodel::ClassHOW->Metamodel::Trusting Metamodel::ClassHOW->Any Metamodel::ClassHOW->Metamodel::Naming Metamodel::ClassHOW->Metamodel::Documenting Metamodel::ClassHOW->Metamodel::Versioning Metamodel::ClassHOW->Metamodel::Stashing Metamodel::ClassHOW->Metamodel::AttributeContainer Metamodel::ClassHOW->Metamodel::Finalization Metamodel::ClassHOW->Metamodel::MethodContainer Metamodel::ClassHOW->Metamodel::PrivateMethodContainer Metamodel::ClassHOW->Metamodel::MultiMethodContainer Metamodel::ClassHOW->Metamodel::RoleContainer Metamodel::ClassHOW->Metamodel::MultipleInheritance Metamodel::ClassHOW->Metamodel::DefaultParent Metamodel::ClassHOW->Metamodel::C3MRO Metamodel::ClassHOW->Metamodel::MROBasedMethodDispatch Metamodel::ClassHOW->Metamodel::MROBasedTypeChecking Metamodel::ClassHOW->Metamodel::BUILDPLAN Metamodel::ClassHOW->Metamodel::Mixins Metamodel::ClassHOW->Metamodel::BoolificationProtocol

Stand-alone image: vector