Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Perl6 MetaModel

by mkirank (Chaplain)
on Jul 25, 2005 at 13:38 UTC ( #477815=perlquestion: print w/ replies, xml ) Need Help??
mkirank has asked for the wisdom of the Perl Monks concerning the following question:

I am looking at the MetaModel in Pugs and trying to understand
In MetaModel.pm at the beginning there is an import function wherein the following subs are put in the name space
my $caller_pkg = caller(); # meta model helpers *{$caller_pkg . '::class'} = \&class; *{$caller_pkg . '::role'} = \&role; # instance attribute access helpers *{$caller_pkg . '::_'} = \&_; # class attribute access helpers *{$caller_pkg . '::__'} = \&__;
when the Object module is loaded the sub class in the Metamodel is called.

What happens when the below code is executed ?
also how does 2 parameters gets passed to the class method (name and params) ?
how do those subs with "DUMMY" get created

class 'Perl6::Object' => { 'class' => { methods => { # the default .new() 'new' => sub { my ($class, %params) = @_; return $class->bless(undef, %params); }, .... .... ## rest of the code

This gives the following in class ($name and $params)
name is Perl6::Object params is $VAR1 = { 'class' => { 'methods' => { 'CREATE' => sub { "DUMMY" }, 'bless' => sub { "DUMMY" }, 'isa' => sub { "DUMMY" }, 'new' => sub { "DUMMY" }, 'can' => sub { "DUMMY" } } }, 'instance' => { 'methods' => { 'isa' => $VAR1->{'class'}{'me +thods'}{'isa'}, 'DESTROYALL' => sub { "DUMMY" + }, 'BUILDALL' => sub { "DUMMY" } +, 'can' => $VAR1->{'class'}{'me +thods'}{'can'} }, 'submethods' => { 'BUILD' => sub { "DUMMY" } } } };

Comment on Perl6 MetaModel
Select or Download Code
Re: Perl6 MetaModel
by stvn (Monsignor) on Jul 25, 2005 at 14:56 UTC
    Greetings mkirank,
    In MetaModel.pm at the beginning there is an import function wherein the following subs are put in the name space

    It should be noted that these functions (class, role) are merely for helper functions, and will not be part of the eventual Perl 6 metamodel. They exist mostly to make class and role composition easier during testing. As for the (_ and __) functions, those are to make class attribute access easier, so you can say _('$.foo') which will eventually become just $.foo in Perl 6.

    when the Object module is loaded the sub class in the Metamodel is called.

    Yes, this is because Object (the base Object class in the Perl 6 OO system) is now defined purely by the meta-model itself. The other classes in the MetaModel folder are the "meta" level components, while the Object is a "user" level component.

    Of course the lines between "user" and "meta" are blurred because Perl 6 is a highly reflective OO language, and you will have access to the "meta" level at all times.

    What happens when the below code is executed ?

    The $name and $params are passed to Perl6::Class->new(), which then composes the Perl6::MetaClass for that given class, and sets up the new class within the runtime environment. It might be useful to think of the class model like this:

    • A MetaClass has a method table, attribute descriptions and superclass list.
    • A Class has a metaclass instance.
    • An Instance has a Class pointer and local attribute storage

    how do those subs with "DUMMY" get created

    This is just the way Data::Dumper represents the internals of a sub. I have nothing to do with it :)

    I apologize for the lack of documentation in these packages right now. I did not want to write too much until I felt the design was more finalized. I might try to write something this week if I have time.

    You might also find the Javascript and Java versions interesting and/or informative. The Javascript version is mostly complete, except for Roles and class attributes, while the Java version is much less complete.

    -stvn
      Thanks stvn :-) ... This clears some things up ...what sort of documentation were you thinking of , since i am going through this , I would be able to help on that front ..
      -Kiran
        what sort of documentation were you thinking of , since i am going through this , I would be able to help on that front

        I wanted to document the individual methods for each class, and then have one "design" document about how they all interact. Any help is very much appreciated. If you have a pugs committer bit, you can just start writing.

        -stvn

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://477815]
Approved by Corion
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-04-19 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (483 votes), past polls