develooper Front page | perl.perl6.users | Postings from October 2020

Metamodel parent and return values ...

Thread Next
From:
Paul Procacci
Date:
October 30, 2020 06:59
Subject:
Metamodel parent and return values ...
Message ID:
CAFbbPujT3a8-XoOQqmztXd8fgEcSjwv31sO1Nhak26yOGSRjEA@mail.gmail.com
Defining classes outside of raku ....

I'm designing a program that would be easiest to have classes created at
runtime.
I've been reading the following page:

https://docs.raku.org/type/Metamodel::ClassHOW

While I believe creating the class itself is working, I'm unsure where it's
documented about setting the parent.

Here is what I have ... trimmed.

#################################################################
use JSON::Pretty;
use Staticish;

unit class MyClass is Static;

method client(::?CLASS:D: Str:D $service! --> MyClass)
{
        my %data := from-json %?RESOURCES{$service}.slurp;
        my $type = Metamodel::ClassHOW.new_type(
                name => $service,
                ver => v0.0.1,
                auth => 'github:me'
        );

        $type.HOW.add_parent($type, 'MyClass');
        $type.HOW.compose($type);
        $type.new;
}
#################################################################

Now when I try running the above, I get:

Type check failed for return value; expected MyClass but got SomeService
("")

Is add_parent in this context not doing what I expect it to do?
I should rephrase that question.  I know it's not doing what I expect it to
do, but is this the right method?
... if it is, returning a class which is a child of another class should
satisfy the return value requirements and I would expect this to work.

Any pointers in the right direction are much appreciated.

Thanks in advance,
Paul Procacci
-- 
__________________

:(){ :|:& };:

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About