1 # Copyright 2008, The Perl Foundation.
6 yaml_dumper.pir - PIR version of a YAML dumper, ala Data::Dumper
15 # dump the P0 register
18 # dump the P0 register, with "name"
23 .include "library/yaml_dumper.pir"
28 PIR implementation of Perl 5's Data::Dumper module to dump YAML format.
32 # first method prints usage information
33 .sub __library_dumper_onload
35 print "\tload_bytecode \"library/YAML/Dumper.pir\"\n"
37 print "\tnew yaml, \"YAML::Dumper\"\n"
38 print "\tyaml.\"yaml\"( foo, \"foo\" )\n\n"
42 .include "errors.pasm"
46 This library provides the following functions:
50 =item yaml( pmc, ?name, ?indent] )
52 This is the public (non object) interface to the yaml dumper library.
58 Required. The PMC to dump.
62 Optional. The name of the PMC.
66 Optional. The indent used at the start of each line printed.
70 B<Note:> This function currently returns nothing. It should return
71 the dumped data as a string, like Perl's Data::Dumper. Instead,
72 everything is printed out using C<print>.
74 B<Note: #2> Hash keys are now sorted using C<_sort()> (library/sort.pir)
80 .param string name :optional
81 .param int has_name :opt_flag
82 .param string ident :optional
83 .param int has_ident :opt_flag
85 $P2 = _global_dumper()
86 if has_ident goto w_ident
87 unless has_name goto wo_name # XXX argument order, opt 1st
94 $P2."yaml"(p, name, ident)
98 =item _register_dumper( id, sub )
100 Registers a dumper for new PMC type. B<UNIMPLEMENTED>
101 But see B<method __dump> below.
107 the PMC id, as returned by the C<typeof> op.
111 a Sub pmc, that gets called in order to dump the content of the given PMC
117 sub = find_name "_dump_PerlArray"
118 _register_dumper( .PerlArray, sub )
120 This function returns nothing.
124 .sub _register_dumper
127 $P2 = _global_dumper()
128 $P2."registerDumper"(id, s)
131 =item __dump(pmc yaml, str label) method
133 If a method C<__dump> exists in the namespace of the class, it will be
134 called with the current dumper object and the label of the PMC.
136 =item yaml =_global_dumper() B<(internal)>
138 Internal helper function.
140 Returns the global dumper instance used by the non object interface.
147 .local int is_defined
149 get_class yd_class, "YAML::Dumper"
150 if null yd_class goto load_yd_pir
154 load_bytecode "library/YAML/Dumper.pir"
155 get_class yd_class, "YAML::Dumper"
156 if null yd_class goto no_class
160 print "fatal error: failure while loading library/YAML/Dumper.pir\n"
164 errorsoff .PARROT_ERRORS_GLOBALS_FLAG
165 find_global self, "YAML::Dumper", "global"
166 errorson .PARROT_ERRORS_GLOBALS_FLAG
167 if null self goto create_type
170 new self, "YAML::Dumper"
171 store_global "YAML::Dumper", "global", self
181 Jens Rieks E<lt>parrot at jensbeimsurfen dot deE<gt> is the author
183 Please send patches and suggestions to the Perl 6 Internals mailing list.
187 Copyright (C) 2004-2008, The Perl Foundation.
195 # vim: expandtab shiftwidth=4 ft=pir: