Author: leo
Date: Sun Jul 31 11:04:11 2005
New Revision: 8760

Modified:
   trunk/runtime/parrot/library/dumper.imc
   trunk/t/library/dumper.t
Log:
test a custom __dump method; update docs

Modified: trunk/runtime/parrot/library/dumper.imc
==============================================================================
--- trunk/runtime/parrot/library/dumper.imc     (original)
+++ trunk/runtime/parrot/library/dumper.imc     Sun Jul 31 11:04:11 2005
@@ -92,7 +92,8 @@ ex:
 
 =item _register_dumper( id, sub )
 
-Registers a dumper for new PMC type.
+Registers a dumper for new PMC type. B<UNIMPLEMENTED>
+But see B<method __dunp> below.
 
 =over 4
 
@@ -124,6 +125,11 @@ This function returns nothing.
     $P2."registerDumper"(id, s)
 .end
 
+=item __dump(pmc dumper, str label) method
+
+If a method C<__dump> exists in the namespace of the class, it will be
+called with the current dumper object and the label of the PMC.
+
 =item dumper =_global_dumper() B<(internal)>
 
 Internal helper function.

Modified: trunk/t/library/dumper.t
==============================================================================
--- trunk/t/library/dumper.t    (original)
+++ trunk/t/library/dumper.t    Sun Jul 31 11:04:11 2005
@@ -18,7 +18,7 @@ Tests data dumping.
 
 use strict;
 
-use Parrot::Test tests => 26;
+use Parrot::Test tests => 27;
 
 # no. 1
 pir_output_is(<<'CODE', <<'OUT', "dumping array of sorted numbers");
@@ -932,5 +932,45 @@ CODE
 ]
 OUTPUT
 
+# no. 27
+pir_output_is(<<'CODE', <<'OUTPUT', "custom dumper");
+.sub main @MAIN
+    .local pmc o, s,ds, cl
+    cl = subclass 'ResizablePMCArray', 'bar'
+    .local int id
+    id = typeof cl
+    o = new id
+    _dumper(s)
+.end
+
+.namespace ["bar"]
+.sub __init method
+    .local pmc ar
+    ar = getattribute self, '__value'
+    push ar, 1
+    push ar, 2
+.end
+
+.sub __dump method
+    .param pmc dumper
+    .param string label
+    print " __value => { \n"
+    .local pmc ar
+    ar = getattribute self, '__value'
+    dumper.'dump'('attr', ar)
+    print "\n}"
+.end
+.namespace ['']
+.include 'library/dumper.imc'
+
+CODE
+"VAR1" => PMC 'bar'  __value => { 
+ResizablePMCArray (size:2) [
+    1,
+    2
+]
+}
+OUTPUT
+
 # pir_output_is(<<'CODE', <<'OUTPUT', "dumping IntegerArray PMC");
 # pir_output_is(<<'CODE', <<'OUTPUT', "dumping FloatValArray PMC");

Reply via email to