Show
Ignore:
Timestamp:
08/06/05 23:00:58 (3 years ago)
Author:
Stevan
Message:

Perl6::MetaModel? - (p5)
* $?CLASS now returns the ::Class object
* all methods and attributes are now associated with the ::Class object

instead of just the class name

* improved the name of ::get_obj_id to ::get_P6opaque_instance_id so that

no one will try to use it :P

* also added ::get_P6opaque_instance_class to peek into the class slot

(needed this for submethods)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • perl5/Perl6-MetaModel/lib/Perl6/Class.pm

    r6093 r6094  
    4545 
    4646sub _apply_class_to_environment { 
    47     my ($self) = @_; 
     47    my ($self) = @_;     
    4848    my ($name) = $self->{instance_data}->{name}; 
    4949    # create the package ... 
     
    5353        \$$name\:\:META = undef; 
    5454        1; 
    55     |; 
     55    |;     
    5656    eval $code || confess "Could not initialize class '$name'";    
     57    _create_metaclass($self);     
     58    _build_class($self);      
    5759    # alias the full name ... 
    5860    eval {   
     
    6163    }; 
    6264    confess "Could not create full name " . $self->{instance_data}->{identifier} . " : $@" if $@;    
    63     _build_class($self);  
    6465} 
    6566 
     
    9394} 
    9495 
    95 sub _build_class { 
     96sub _create_metaclass { 
    9697    my ($self) = @_; 
    97      
    9898    my ($name, $version, $authority) = ($self->{instance_data}->{name}, $self->{instance_data}->{version}, $self->{instance_data}->{authority});     
    9999 
     
    129129        $self->{instance_data}->{meta} = $meta;  
    130130    }; 
    131     confess "Could not initialize the metaclass for $name : $@" if $@;  
     131    confess "Could not initialize the metaclass for $name : $@" if $@;      
     132} 
     133 
     134sub _build_class { 
     135    my ($self) = @_; 
     136 
     137    my $meta = $self->{instance_data}->{meta}; 
    132138 
    133139    my $superclasses = $self->{instance_data}->{params}->{is}; 
     
    136142    if (my $instance = $self->{instance_data}->{params}->{instance}) { 
    137143 
    138         ::dispatch($meta, 'add_method', ('BUILD' => Perl6::Method->create_submethod($name => $instance->{BUILD}))) 
     144        ::dispatch($meta, 'add_method', ('BUILD' => Perl6::Method->create_submethod($self => $instance->{BUILD}))) 
    139145            if exists $instance->{BUILD};             
    140         ::dispatch($meta, 'add_method', ('DESTROY' => Perl6::Method->create_submethod($name => $instance->{DESTROY}))) 
     146        ::dispatch($meta, 'add_method', ('DESTROY' => Perl6::Method->create_submethod($self => $instance->{DESTROY}))) 
    141147            if exists $instance->{DESTROY}; 
    142148             
     
    144150            foreach (keys %{$instance->{methods}}) { 
    145151                if (/^_/) { 
    146                     ::dispatch($meta, 'add_method', ($_ => Perl6::Method->create_private_method($name, $instance->{methods}->{$_}))); 
     152                    ::dispatch($meta, 'add_method', ($_ => Perl6::Method->create_private_method($self, $instance->{methods}->{$_}))); 
    147153                } 
    148154                else { 
    149                     ::dispatch($meta, 'add_method', ($_ => Perl6::Method->create_instance_method($name, $instance->{methods}->{$_}))); 
     155                    ::dispatch($meta, 'add_method', ($_ => Perl6::Method->create_instance_method($self, $instance->{methods}->{$_}))); 
    150156                } 
    151157            } 
    152158        } 
    153159        if (exists $instance->{submethods}) { 
    154             ::dispatch($meta, 'add_method', ($_ => Perl6::Method->create_submethod($name, $instance->{submethods}->{$_}))) 
     160            ::dispatch($meta, 'add_method', ($_ => Perl6::Method->create_submethod($self, $instance->{submethods}->{$_}))) 
    155161                foreach keys %{$instance->{submethods}}; 
    156162        }         
     
    162168                } 
    163169                ::dispatch($meta, 'add_attribute', ( 
    164                     $attr => Perl6::Instance::Attribute->new($name => $attr, $props) 
     170                    $attr => Perl6::Instance::Attribute->new($self => $attr, $props) 
    165171                ));               
    166172            } 
     
    176182                } 
    177183                ::dispatch($meta, 'add_attribute', ( 
    178                     $attr => Perl6::Class::Attribute->new($name => $attr, $props) 
     184                    $attr => Perl6::Class::Attribute->new($self => $attr, $props) 
    179185                )); 
    180186            }             
     
    184190            foreach my $label (keys %{$class->{methods}}) { 
    185191                if ($label =~ /^_/) { 
    186                     ::dispatch($meta, 'add_method', ($label => Perl6::Method->create_private_method($name, $class->{methods}->{$label}))); 
     192                    ::dispatch($meta, 'add_method', ($label => Perl6::Method->create_private_method($self, $class->{methods}->{$label}))); 
    187193                } 
    188194                else { 
    189                     ::dispatch($meta, 'add_method', ($label => Perl6::Method->create_class_method($name, $class->{methods}->{$label}))); 
     195                    ::dispatch($meta, 'add_method', ($label => Perl6::Method->create_class_method($self, $class->{methods}->{$label}))); 
    190196                } 
    191197            }