What's a dump stream actually going to look like? E.g.,

    $a = [1, 2, 3];
    print dump($a);

1: PMC PerlArray
2: 3              # element count
3: PMC PerlInt    # [0]
4: 1              #   value
5: PMC PerlInt    # [1]
6: 2              #   value
7: PMC PerlInt    # [2]
8: 3              #   value

Fine and good. But dump must handle object graphs, which can be
recursive or self-referential or whatnot:

    $a = { b => undef };
    $b = { a => $a    };
    $a->{b} = $b;
    print dump($a);

1: PMC PerlHash
2: 1              # key-value count
3: PMC PerlString # keys[0]
4: "b"            #   value
5: PMC PerlHash   # values[0]
6: 1              #   key-value count
7: PMC PerlString #   keys[0]
8: "a"            #     value
9: !!!!!!!

Panic! Dump needs to refer to line 4 again, or else recurse! How?

Most serializers use a seen hash not only to indicate that an object has
been seen, but also to remember a name or number for that object. If
dump had remembered &$a => line 4, it could finish off with something
like...

9: Again 4        #   values[0]

A seen hash is also threadsafe, can be interrupted by DoD, and is safe
for recursion. (By "threadsafe," I mean that unchanged data structures
can be safely serialized from multiple threads without ill effect or
possibility of deadlock.)

--
 
Gordon Henriksen
IT Manager
ICLUBcentral Inc.
[EMAIL PROTECTED]


Reply via email to