/
RoleToInstanceApplier.nqp
47 lines (31 loc) · 1.05 KB
/
RoleToInstanceApplier.nqp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
=begin
=head1 TITLE
Perl6::Metamodel::RoleToInstanceApplier
=head1 DESCRIPTION
Applies roles to an instance.
=head1 METHODS
=over 4
=item apply(target, composees)
Applies all of the composees to an instance.
=end
class Perl6::Metamodel::RoleToInstanceApplier;
method apply($target, @composees) {
# Make anonymous subclass.
my $*SCOPE := 'anon';
my $subclass := $target.HOW.new('');
$subclass.HOW.add_parent($subclass, $target.WHAT);
# Add all of our given composees to it.
for @composees {
$subclass.HOW.add_composable($subclass, $_);
}
# Complete construction of anonymous subclass and then rebless the target
# into it. XXX This bit is a tad Parrot-specific at the moment; need to
# better encapsulate reblessing. Also we need to make a fake instance of
# the subclass to have Parrot internally form it's various bits.
my $new_class := $subclass.HOW.compose($subclass);
$new_class.CREATE();
pir::rebless_subclass__vPP($target, $new_class.HOW.get_parrotclass($new_class));
}
=begin
=back
=end