Author: pmichaud
Date: Wed Nov 12 22:24:06 2008
New Revision: 32594
Modified:
trunk/runtime/parrot/library/P6object.pir
trunk/t/library/p6object.t
Log:
[p6object]: Add 'add_method' method to P6metaclass.
Modified: trunk/runtime/parrot/library/P6object.pir
==============================================================================
--- trunk/runtime/parrot/library/P6object.pir (original)
+++ trunk/runtime/parrot/library/P6object.pir Wed Nov 12 22:24:06 2008
@@ -231,6 +231,27 @@
.end
+=item add_method(name, method, [, 'to'=>parrotclass])
+
+Add C<method> with C<name> to C<parrotclass>.
+
+=cut
+
+.sub 'add_method' :method
+ .param string name
+ .param pmc method
+ .param pmc options :slurpy :named
+
+ $P0 = options['to']
+ unless null $P0 goto have_to
+ $P0 = self
+ have_to:
+ .local pmc parrotclass
+ parrotclass = self.'get_parrotclass'($P0)
+ parrotclass.'add_method'(name, method)
+.end
+
+
=item register(parrotclass [, 'name'=>name] [, 'protoobject'=>proto] [,
'parent'=>parentclass] [, 'hll'=>hll])
Sets objects of type C<parrotclass> to use C<protoobject>,
Modified: trunk/t/library/p6object.t
==============================================================================
--- trunk/t/library/p6object.t (original)
+++ trunk/t/library/p6object.t Wed Nov 12 22:24:06 2008
@@ -26,7 +26,7 @@
test_namespace.'export_to'(curr_namespace, exports)
## set our plan
- plan(232)
+ plan(233)
## make sure we can load the P6object library
push_eh load_fail
@@ -151,7 +151,15 @@
is_same($P0, jklproto, 'return from .new_class =:= Foo::JKL')
$P0 = get_hll_global 'Foo::JKL'
isa_nok($P0, 'P6protoobject', '["Foo::JKL"]')
- p6obj_tests(jklproto, 'Foo::JKL', 'shortname'=>'JKL', 'isa'=>'P6object',
'can'=>'foo')
+ jklobj = p6obj_tests(jklproto, 'Foo::JKL', 'shortname'=>'JKL',
'isa'=>'P6object', 'can'=>'foo')
+
+ ## add a method to a class
+ $P0 = get_hll_global ['ABC'], 'foo'
+ p6meta.'add_method'('bar', $P0, 'to'=>jklproto)
+ jklobj = new ['Foo';'JKL']
+ $S0 = jklobj.'bar'()
+ is($S0, 'ABC::foo', 'JKL.bar via add_method')
+
=for never