Changeset 7036

Show
Ignore:
Timestamp:
09/18/05 18:13:08 (3 years ago)
Author:
stevan
Message:

Perl6::MetaModel? 2.0 -
* sketched out role(Role) in psyche
* Role now calls resolve() on it's won in MiniMetaMode?_w_Roles
* added test to show that the model can host inside-out objects
* other misc. minor tweaks

Location:
perl5/Perl6-MetaModel2.0
Files:
1 added
6 modified

Legend:

Unmodified
Added
Removed
  • perl5/Perl6-MetaModel2.0/docs/MiniMetaModel_w_Role.pl

    r7029 r7036  
    194194# Bootstrap -> Role does Role 
    195195::opaque_instance_attrs($Role)->{'@:roles'} = [ $Role ]; 
    196 $_resolve->($Role); 
     196$Role->resolve(); # Role can resolve itself now :) 
    197197 
    198198# Class gets a special case Does 
  • perl5/Perl6-MetaModel2.0/lib/Perl6/MetaModel.pm

    r7026 r7036  
    1717    my $pkg = caller; 
    1818    *{"${pkg}::class"} = \&class; 
    19     *{"${pkg}::role"}  = \&role;     
     19    *{"${pkg}::role"}  = \&role;    
     20     
     21    *{"${pkg}::__"}  = \&__;         
    2022} 
    2123 
     
    2931    ::opaque_instance_attrs($::SELF)->{$attr} = shift if @_; 
    3032    ::opaque_instance_attrs($::SELF)->{$attr};     
     33} 
     34 
     35sub __ { 
     36    my $attr = shift; 
     37    $::CLASS->STORE($attr => shift) if @_; 
     38    $::CLASS->FETCH($attr);   
    3139} 
    3240 
  • perl5/Perl6-MetaModel2.0/lib/chaos.pl

    r7026 r7036  
    7171    $::CALLER::CLASS = undef; 
    7272 
     73    ## WALKMETH and WALKCLASS 
    7374    # these are actually two functions 
    7475    # which are detailed in A12 and are 
     
    117118     
    118119    # DEPRECATED 
     120    # Class attribute are just package level variables now 
    119121    # sub ::make_class_attribute ($) { 
    120122    #     my ($name) = @_; 
     
    124126    # }      
    125127     
     128    # this just initializes the instance attribute container type, in 
     129    # perl 6 this should be done automatically 
    126130    sub ::instantiate_attribute_container ($) { 
    127131        my ($attr) = @_; 
  • perl5/Perl6-MetaModel2.0/lib/gnosis.pl

    r6983 r7036  
    3030 
    3131## create the body of 'add_method' here,..  
    32 my $_add_method = sub { 
    33     my ($self, $label, $method) = @_; 
    34     (defined $label && $label) 
    35         || confess "You must supply a valid method label"; 
    36     (blessed($method)) 
    37         || confess "A method must be a blessed Perl6::Method object"; 
     32{ 
     33    my $_add_method = sub { 
     34        my ($self, $label, $method) = @_; 
     35        (defined $label && $label) 
     36            || confess "You must supply a valid method label"; 
     37        (blessed($method)) 
     38            || confess "A method must be a blessed Perl6::Method object"; 
    3839     
    39     ::bind_method_to_class($method, $self); 
     40        ::bind_method_to_class($method, $self); 
    4041         
    41     if (blessed($method) eq 'Perl6::Method'   || 
    42         blessed($method) eq 'Perl6::Submethod') { 
    43         ::opaque_instance_attrs($self)->{'%:methods'}->{$label} = $method; 
    44     } 
    45     elsif (blessed($method) eq 'Perl6::ClassMethod') { 
    46         ::opaque_instance_attrs($self)->{'%:class_methods'}->{$label} = $method;                 
    47     } 
    48     elsif (blessed($method) eq 'Perl6::PrivateMethod') { 
    49         ::opaque_instance_attrs($self)->{'%:private_methods'}->{$label} = $method;                 
    50     }             
    51     else { 
    52         confess "I do not recognize the method type ($method)"; 
    53     } 
    54 }; 
     42        if (blessed($method) eq 'Perl6::Method'   || 
     43            blessed($method) eq 'Perl6::Submethod') { 
     44            ::opaque_instance_attrs($self)->{'%:methods'}->{$label} = $method; 
     45        } 
     46        elsif (blessed($method) eq 'Perl6::ClassMethod') { 
     47            ::opaque_instance_attrs($self)->{'%:class_methods'}->{$label} = $method;                 
     48        } 
     49        elsif (blessed($method) eq 'Perl6::PrivateMethod') { 
     50            ::opaque_instance_attrs($self)->{'%:private_methods'}->{$label} = $method;                 
     51        }             
     52        else { 
     53            confess "I do not recognize the method type ($method)"; 
     54        } 
     55    }; 
    5556 
    56 # and use it to add itself to the $::Class 
    57 $_add_method->($::Class, 'add_method', ::make_method($_add_method)); 
    58  
     57    # and use it to add itself to the $::Class 
     58    $_add_method->($::Class, 'add_method', ::make_method($_add_method)); 
     59} 
    5960# ... now we have all we need to construct our $::Class  
    6061 
  • perl5/Perl6-MetaModel2.0/lib/pneuma.pl

    r7032 r7036  
    88# This is pneuma, this creates ::Object, ::Package and ::Module 
    99 
     10# From Answers.com: 
    1011# According to the Gnostics, the Demiurge was able to endow man  
    1112# only with psyche (sensuous soul) — the pneuma (rational soul)  
    1213# having been added by God. 
     14 
     15## (see psyche.pl for more information) 
    1316 
    1417$::Object  = undef; 
  • perl5/Perl6-MetaModel2.0/lib/psyche.pl

    r7032 r7036  
    217217})); 
    218218 
     219=pod 
     220 
     221------------------------------------------------------------------------------- 
     222 
     223This is a rough sketch of that role(Role) might look like.  
     224 
     225role Role { 
     226    has @:roles is rw;  # makes the roles mutator/accessor 
     227 
     228    # -----------------------------------------------       
     229    # this collects a unique list of roles  
     230    # gather recursively, &resolve uses it 
     231    # to gather all the roles to be 'resolved' 
     232    # -----------------------------------------------       
     233    method collect_all_roles () { "<implemented>" }   
     234 
     235    # -----------------------------------------------     
     236    # NOTE: 
     237    # I am not sure I need to define these attrs in  
     238    # the Role it can remain an implementation detail  
     239    # for the methods described below. 
     240    # ----------------------------------------------- 
     241    # has %:methods; 
     242    # has %:attributes; 
     243    # -----------------------------------------------     
     244       
     245    # -----------------------------------------------   
     246    # collects all the roles, and applies them to the 
     247    # invocant, which usually will be a class, but it 
     248    # can be a role too. 
     249    # -----------------------------------------------     
     250    method resolve () { "<implemented>" } 
     251 
     252    # -----------------------------------------------     
     253    # NOTE: 
     254    # &resolve requires the following interface 
     255    # to be implemented, so it makes abstract  
     256    # methods which must be implemented 
     257    # ----------------------------------------------- 
     258 
     259    method add_method; 
     260    method get_method; 
     261    method has_method; 
     262    method get_method_list;         
     263     
     264    method add_attribute; 
     265    method get_attribute; 
     266    method has_attribute; 
     267    method get_attribute_list;             
     268} 
     269 
     270------------------------------------------------------------------------------- 
     271Random Thoughts on Role state: 
     272------------------------------------------------------------------------------- 
     273 
     274What if Roles could provide their own BUILD submethods? This would  
     275mean that BUILD methods would need to be collected in some way. 
     276So that BUILDALL not only ran the Class BUILD submethod, but any 
     277Role BUILD submethods. It is important that submethods are used 
     278because they will not get inherited. This provides more predictable  
     279behavior to class consturction because it isolates the Role specifc 
     280code to the class that consumed it. 
     281 
     282------------------------------------------------------------------------------- 
     283 
     284=cut 
     285 
    2192861;