Changeset 7036
- Timestamp:
- 09/18/05 18:13:08 (3 years ago)
- Location:
- perl5/Perl6-MetaModel2.0
- Files:
-
- 1 added
- 6 modified
-
docs/MiniMetaModel_w_Role.pl (modified) (1 diff)
-
lib/Perl6/MetaModel.pm (modified) (2 diffs)
-
lib/chaos.pl (modified) (3 diffs)
-
lib/gnosis.pl (modified) (1 diff)
-
lib/pneuma.pl (modified) (1 diff)
-
lib/psyche.pl (modified) (1 diff)
-
t/31_inside_out_objects.t (added)
Legend:
- Unmodified
- Added
- Removed
-
perl5/Perl6-MetaModel2.0/docs/MiniMetaModel_w_Role.pl
r7029 r7036 194 194 # Bootstrap -> Role does Role 195 195 ::opaque_instance_attrs($Role)->{'@:roles'} = [ $Role ]; 196 $ _resolve->($Role);196 $Role->resolve(); # Role can resolve itself now :) 197 197 198 198 # Class gets a special case Does -
perl5/Perl6-MetaModel2.0/lib/Perl6/MetaModel.pm
r7026 r7036 17 17 my $pkg = caller; 18 18 *{"${pkg}::class"} = \&class; 19 *{"${pkg}::role"} = \&role; 19 *{"${pkg}::role"} = \&role; 20 21 *{"${pkg}::__"} = \&__; 20 22 } 21 23 … … 29 31 ::opaque_instance_attrs($::SELF)->{$attr} = shift if @_; 30 32 ::opaque_instance_attrs($::SELF)->{$attr}; 33 } 34 35 sub __ { 36 my $attr = shift; 37 $::CLASS->STORE($attr => shift) if @_; 38 $::CLASS->FETCH($attr); 31 39 } 32 40 -
perl5/Perl6-MetaModel2.0/lib/chaos.pl
r7026 r7036 71 71 $::CALLER::CLASS = undef; 72 72 73 ## WALKMETH and WALKCLASS 73 74 # these are actually two functions 74 75 # which are detailed in A12 and are … … 117 118 118 119 # DEPRECATED 120 # Class attribute are just package level variables now 119 121 # sub ::make_class_attribute ($) { 120 122 # my ($name) = @_; … … 124 126 # } 125 127 128 # this just initializes the instance attribute container type, in 129 # perl 6 this should be done automatically 126 130 sub ::instantiate_attribute_container ($) { 127 131 my ($attr) = @_; -
perl5/Perl6-MetaModel2.0/lib/gnosis.pl
r6983 r7036 30 30 31 31 ## 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"; 38 39 39 ::bind_method_to_class($method, $self);40 ::bind_method_to_class($method, $self); 40 41 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 }; 55 56 56 # and use it to add itself to the $::Class57 $_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 } 59 60 # ... now we have all we need to construct our $::Class 60 61 -
perl5/Perl6-MetaModel2.0/lib/pneuma.pl
r7032 r7036 8 8 # This is pneuma, this creates ::Object, ::Package and ::Module 9 9 10 # From Answers.com: 10 11 # According to the Gnostics, the Demiurge was able to endow man 11 12 # only with psyche (sensuous soul) — the pneuma (rational soul) 12 13 # having been added by God. 14 15 ## (see psyche.pl for more information) 13 16 14 17 $::Object = undef; -
perl5/Perl6-MetaModel2.0/lib/psyche.pl
r7032 r7036 217 217 })); 218 218 219 =pod 220 221 ------------------------------------------------------------------------------- 222 223 This is a rough sketch of that role(Role) might look like. 224 225 role 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 ------------------------------------------------------------------------------- 271 Random Thoughts on Role state: 272 ------------------------------------------------------------------------------- 273 274 What if Roles could provide their own BUILD submethods? This would 275 mean that BUILD methods would need to be collected in some way. 276 So that BUILDALL not only ran the Class BUILD submethod, but any 277 Role BUILD submethods. It is important that submethods are used 278 because they will not get inherited. This provides more predictable 279 behavior to class consturction because it isolates the Role specifc 280 code to the class that consumed it. 281 282 ------------------------------------------------------------------------------- 283 284 =cut 285 219 286 1;
