<commit_before># Copyright 2008, The Perl Foundation.
# $Id$

=head1 TITLE

yaml_dumper.pir - PIR version of a YAML dumper, ala Data::Dumper

=head1 VERSION

version 0.1

=head1 SYNOPSIS

    ...
    # dump the P0 register
    yaml( P0 )

    # dump the P0 register, with "name"
    yaml( P0, "name" )
    ...

    END
    .include "library/yaml_dumper.pir"


=head1 DESCRIPTION

    PIR implementation of Perl 5's Data::Dumper module to dump YAML format.

=cut

# first method prints usage information
.sub __library_dumper_onload
    print "usage:"
    print "\tload_bytecode \"library/YAML/Dumper.pir\"\n"
    print "\t...\n"
    print "\tnew yaml, \"YAML::Dumper\"\n"
    print "\tyaml.\"yaml\"( foo, \"foo\" )\n\n"
    end
.end

.include "errors.pasm"

=head1 FUNCTIONS

This library provides the following functions:

=over 4

=item yaml( pmc, ?name, ?indent] )

This is the public (non object) interface to the yaml dumper library.

=over 4

=item pmc

Required. The PMC to dump.

=item name

Optional. The name of the PMC.

=item indent

Optional. The indent used at the start of each line printed.

=back

B<Note:> This function currently returns nothing. It should return
the dumped data as a string, like Perl's Data::Dumper. Instead,
everything is printed out using C<print>.

B<Note: #2> Hash keys are now sorted using C<_sort()> (library/sort.pir)

=cut

.sub yaml
    .param pmc p
    .param string name    :optional
    .param int has_name   :opt_flag
    .param string ident   :optional
    .param int has_ident  :opt_flag

    $P2 = _global_dumper()
    if has_ident goto w_ident
    unless has_name goto wo_name        # XXX argument order, opt 1st
    $P2."yaml"(p, name)
    goto ex
wo_name:
    $P2."yaml"(p)
    goto ex
w_ident:
    $P2."yaml"(p, name, ident)
ex:
.end

=item _register_dumper( id, sub )

Registers a dumper for new PMC type. B<EXCEPTION_UNIMPLEMENTED>
But see B<method __dump> below.

=over 4

=item id

the PMC id, as returned by the C<typeof> op.

=item sub

a Sub pmc, that gets called in order to dump the content of the given PMC

=back

For example:

    sub = find_name "_dump_PerlArray"
    _register_dumper( .PerlArray, sub )

This function returns nothing.

=cut

.sub _register_dumper
    .param int id
    .param pmc s
    $P2 = _global_dumper()
    $P2."registerDumper"(id, s)
.end

=item __dump(pmc yaml, 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 yaml =_global_dumper() B<(internal)>

Internal helper function.

Returns the global dumper instance used by the non object interface.

=cut

.sub _global_dumper
    .local pmc self
    .local pmc yd_class
    .local int is_defined

    get_class yd_class, "YAML::Dumper"
    if null yd_class goto load_yd_pir
    goto TYPE_OK

  load_yd_pir:
    load_bytecode "library/YAML/Dumper.pir"
    get_class yd_class, "YAML::Dumper"
    if null yd_class goto no_class
    goto TYPE_OK

  no_class:
    print "fatal error: failure while loading library/YAML/Dumper.pir\n"
    end
TYPE_OK:

    errorsoff .PARROT_ERRORS_GLOBALS_FLAG
    find_global self, "YAML::Dumper", "global"
    errorson .PARROT_ERRORS_GLOBALS_FLAG
    if null self goto create_type

create_type:
    new self, "YAML::Dumper"
    store_global "YAML::Dumper", "global", self

END:
    .return( self )
.end

=back

=head1 AUTHOR

<NAME> E<lt>parrot at jensbeimsurfen dot deE<gt> is the author
and maintainer.
Please send patches and suggestions to the Perl 6 Internals mailing list.

=head1 COPYRIGHT

Copyright (C) 2004-2008, The Perl Foundation.

=cut
<commit_msg>Avoid [DEPRCATED] opcodes. yaml tests still pass.<commit_after># Copyright 2008, The Perl Foundation.
# $Id$

=head1 TITLE

yaml_dumper.pir - PIR version of a YAML dumper, ala Data::Dumper

=head1 VERSION

version 0.1

=head1 SYNOPSIS

    ...
    # dump the P0 register
    yaml( P0 )

    # dump the P0 register, with "name"
    yaml( P0, "name" )
    ...

    END
    .include "library/yaml_dumper.pir"


=head1 DESCRIPTION

    PIR implementation of Perl 5's Data::Dumper module to dump YAML format.

=cut

# first method prints usage information
.sub __library_dumper_onload
    print "usage:"
    print "\tload_bytecode \"library/YAML/Dumper.pir\"\n"
    print "\t...\n"
    print "\tnew yaml, \"YAML::Dumper\"\n"
    print "\tyaml.\"yaml\"( foo, \"foo\" )\n\n"
    end
.end

.include "errors.pasm"

=head1 FUNCTIONS

This library provides the following functions:

=over 4

=item yaml( pmc, ?name, ?indent] )

This is the public (non object) interface to the yaml dumper library.

=over 4

=item pmc

Required. The PMC to dump.

=item name

Optional. The name of the PMC.

=item indent

Optional. The indent used at the start of each line printed.

=back

B<Note:> This function currently returns nothing. It should return
the dumped data as a string, like Perl's Data::Dumper. Instead,
everything is printed out using C<print>.

B<Note: #2> Hash keys are now sorted using C<_sort()> (library/sort.pir)

=cut

.sub yaml
    .param pmc p
    .param string name    :optional
    .param int has_name   :opt_flag
    .param string ident   :optional
    .param int has_ident  :opt_flag

    $P2 = _global_dumper()
    if has_ident goto w_ident
    unless has_name goto wo_name        # XXX argument order, opt 1st
    $P2."yaml"(p, name)
    goto ex
wo_name:
    $P2."yaml"(p)
    goto ex
w_ident:
    $P2."yaml"(p, name, ident)
ex:
.end

=item _register_dumper( id, sub )

Registers a dumper for new PMC type. B<EXCEPTION_UNIMPLEMENTED>
But see B<method __dump> below.

=over 4

=item id

the PMC id, as returned by the C<typeof> op.

=item sub

a Sub pmc, that gets called in order to dump the content of the given PMC

=back

For example:

    sub = find_name "_dump_PerlArray"
    _register_dumper( .PerlArray, sub )

This function returns nothing.

=cut

.sub _register_dumper
    .param int id
    .param pmc s
    $P2 = _global_dumper()
    $P2."registerDumper"(id, s)
.end

=item __dump(pmc yaml, 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 yaml =_global_dumper() B<(internal)>

Internal helper function.

Returns the global dumper instance used by the non object interface.

=cut

.sub _global_dumper
    .local pmc self
    .local pmc yd_class
    .local int is_defined

    get_class yd_class, "YAML::Dumper"
    if null yd_class goto load_yd_pir
    goto TYPE_OK

  load_yd_pir:
    load_bytecode "library/YAML/Dumper.pir"
    get_class yd_class, "YAML::Dumper"
    if null yd_class goto no_class
    goto TYPE_OK

  no_class:
    print "fatal error: failure while loading library/YAML/Dumper.pir\n"
    end
TYPE_OK:

    errorsoff .PARROT_ERRORS_GLOBALS_FLAG
    self = get_global ['YAML::Dumper'], 'global'
    errorson .PARROT_ERRORS_GLOBALS_FLAG
    if null self goto create_type

create_type:
    new self, "YAML::Dumper"
    set_global ['YAML::Dumper'], 'global', self

END:
    .return( self )
.end

=back

=head1 AUTHOR

<NAME> E<lt>parrot at jensbeimsurfen dot deE<gt> is the author
and maintainer.
Please send patches and suggestions to the Perl 6 Internals mailing list.

=head1 COPYRIGHT

Copyright (C) 2004-2008, The Perl Foundation.

=cut

{'fraction_non_alphanumeric': 0.09195088676671215, 'fraction_numerical': 0.010368349249658937, 'mean_word_length': 3.2132183908045975, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6598489', 'n_tokens_mistral': 2732, 'n_tokens_neox': 2572, 'n_words': 920}