Changeset 6094
- Timestamp:
- 08/06/05 23:00:58 (3 years ago)
- Location:
- perl5/Perl6-MetaModel
- Files:
-
- 7 modified
-
lib/Perl6/Class.pm (modified) (10 diffs)
-
lib/Perl6/MetaClass.pm (modified) (2 diffs)
-
lib/Perl6/MetaModel.pm (modified) (1 diff)
-
lib/Perl6/Method.pm (modified) (1 diff)
-
lib/Perl6/Object.pm (modified) (1 diff)
-
t/03_DESTROY.t (modified) (7 diffs)
-
t/15_CLASS.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
perl5/Perl6-MetaModel/lib/Perl6/Class.pm
r6093 r6094 45 45 46 46 sub _apply_class_to_environment { 47 my ($self) = @_; 47 my ($self) = @_; 48 48 my ($name) = $self->{instance_data}->{name}; 49 49 # create the package ... … … 53 53 \$$name\:\:META = undef; 54 54 1; 55 |; 55 |; 56 56 eval $code || confess "Could not initialize class '$name'"; 57 _create_metaclass($self); 58 _build_class($self); 57 59 # alias the full name ... 58 60 eval { … … 61 63 }; 62 64 confess "Could not create full name " . $self->{instance_data}->{identifier} . " : $@" if $@; 63 _build_class($self);64 65 } 65 66 … … 93 94 } 94 95 95 sub _ build_class {96 sub _create_metaclass { 96 97 my ($self) = @_; 97 98 98 my ($name, $version, $authority) = ($self->{instance_data}->{name}, $self->{instance_data}->{version}, $self->{instance_data}->{authority}); 99 99 … … 129 129 $self->{instance_data}->{meta} = $meta; 130 130 }; 131 confess "Could not initialize the metaclass for $name : $@" if $@; 131 confess "Could not initialize the metaclass for $name : $@" if $@; 132 } 133 134 sub _build_class { 135 my ($self) = @_; 136 137 my $meta = $self->{instance_data}->{meta}; 132 138 133 139 my $superclasses = $self->{instance_data}->{params}->{is}; … … 136 142 if (my $instance = $self->{instance_data}->{params}->{instance}) { 137 143 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}))) 139 145 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}))) 141 147 if exists $instance->{DESTROY}; 142 148 … … 144 150 foreach (keys %{$instance->{methods}}) { 145 151 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}->{$_}))); 147 153 } 148 154 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}->{$_}))); 150 156 } 151 157 } 152 158 } 153 159 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}->{$_}))) 155 161 foreach keys %{$instance->{submethods}}; 156 162 } … … 162 168 } 163 169 ::dispatch($meta, 'add_attribute', ( 164 $attr => Perl6::Instance::Attribute->new($ name=> $attr, $props)170 $attr => Perl6::Instance::Attribute->new($self => $attr, $props) 165 171 )); 166 172 } … … 176 182 } 177 183 ::dispatch($meta, 'add_attribute', ( 178 $attr => Perl6::Class::Attribute->new($ name=> $attr, $props)184 $attr => Perl6::Class::Attribute->new($self => $attr, $props) 179 185 )); 180 186 } … … 184 190 foreach my $label (keys %{$class->{methods}}) { 185 191 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}))); 187 193 } 188 194 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}))); 190 196 } 191 197 } -
perl5/Perl6-MetaModel/lib/Perl6/MetaClass.pm
r6092 r6094 7 7 use Scalar::Util 'blessed'; 8 8 use Carp 'confess'; 9 10 use Perl6::MetaClass::Dispatcher;11 9 12 10 sub new { … … 240 238 'dispatcher' => Perl6::Method->create_instance_method('Perl6::MetaClass' => sub { 241 239 my ($self, $order) = @_; 240 require Perl6::MetaClass::Dispatcher; 242 241 Perl6::MetaClass::Dispatcher->new($self, $order); 243 242 }) -
perl5/Perl6-MetaModel/lib/Perl6/MetaModel.pm
r6093 r6094 76 76 # this means that our code should not try to peak into it 77 77 # and so we should then use some kind of outside mechanism 78 # to get at the object id 79 sub ::get_obj_id { (shift)->{id} } 78 # to get at the object id and class 79 sub ::get_P6opaque_instance_id { (shift)->{id} } 80 sub ::get_P6opaque_instance_class { (shift)->{class} } 80 81 81 82 sub ::meta { -
perl5/Perl6-MetaModel/lib/Perl6/Method.pm
r6089 r6094 37 37 $method = bless sub { 38 38 unless (ref($_[0]) eq 'FORCE') { 39 return ::next_METHOD() if $_[0]->[0]->{class} ne $associated_with; 39 return ::next_METHOD() 40 ## XXX 41 # this should not be accessing either the 42 # instance_data->name slot, but we cannot 43 # do anything about it for now ... 44 if ::get_P6opaque_instance_class($_[0]->[0]) ne $associated_with->{instance_data}->{name}; 40 45 } 41 46 $old->($_[1]); -
perl5/Perl6-MetaModel/lib/Perl6/Object.pm
r6091 r6094 99 99 'isa' => $isa, 100 100 'can' => $can, 101 'id' => sub { ::get_ obj_id(shift) }101 'id' => sub { ::get_P6opaque_instance_id(shift) } 102 102 } 103 103 } -
perl5/Perl6-MetaModel/t/03_DESTROY.t
r5790 r6094 28 28 instance => { 29 29 DESTROY => sub { 30 push @classes_destroyed, ( CLASS . '::DESTROY');30 push @classes_destroyed, ('Foo::DESTROY'); 31 31 } 32 32 } … … 39 39 submethods => { 40 40 DESTROY => sub { 41 push @classes_destroyed, ( CLASS . '::DESTROY');41 push @classes_destroyed, ('Bar::DESTROY'); 42 42 } 43 43 } … … 49 49 instance => { 50 50 DESTROY => sub { 51 push @classes_destroyed, ( CLASS . '::DESTROY');51 push @classes_destroyed, ('Foo::Bar::DESTROY'); 52 52 } 53 53 } … … 77 77 instance => { 78 78 DESTROY => sub { 79 push @classes_destroyed, ( CLASS . '::DESTROY');79 push @classes_destroyed, ('A::DESTROY'); 80 80 } 81 81 } … … 86 86 instance => { 87 87 DESTROY => sub { 88 push @classes_destroyed, ( CLASS . '::DESTROY');88 push @classes_destroyed, ('B::DESTROY'); 89 89 } 90 90 } … … 95 95 instance => { 96 96 DESTROY => sub { 97 push @classes_destroyed, ( CLASS . '::DESTROY');97 push @classes_destroyed, ('C::DESTROY'); 98 98 } 99 99 } … … 104 104 instance => { 105 105 DESTROY => sub { 106 push @classes_destroyed, ( CLASS . '::DESTROY');106 push @classes_destroyed, ('D::DESTROY'); 107 107 } 108 108 } -
perl5/Perl6-MetaModel/t/15_CLASS.t
r5790 r6094 40 40 $val = Foo->this_will_not_die(); 41 41 } '... CLASS can be called from a Class method'; 42 is ($val, 'Foo', '... got the right value from CLASS too');42 isa_ok($val, 'Foo'); 43 43 } 44 44 … … 51 51 $val = $foo->bar(); 52 52 } '... CLASS can be used to call Class methods'; 53 is ($val, 'Foo', '... got the right value from CLASS too');53 isa_ok($val, 'Foo'); 54 54 } 55 55 … … 59 59 $val = $foo->foo(); 60 60 } '... CLASS can be called from an instance method'; 61 is ($val, 'Foo', '... got the right value from CLASS too');61 isa_ok($val, 'Foo'); 62 62 }
