<commit_before>use v6;

class SVG {

    method serialize($tree?, *%named) {
        my $t;
        my $err = "Please pass exactly one argument to SVG.serialize";
        if defined($tree) {
            die $err unless %named.pairs == 0;
            $t = $tree;
        } else {
            die $err unless %named.pairs == 1;
            $t = %named.pairs.[0];
        }
        die 'The XML tree must have a single root node'
            unless 1 == $t.elems && $.is_element($t);
        $.visit($t.list);
    }

    method is_attribute($x) { $x ~~ Pair && $x.value !~~ Array };
    method is_element($x)   { $x ~~ Pair && $x.value ~~ Array };
    method is_text_node($x) { $x ~~ Str };
    method is_node($x)      { $.is_element($x) || $.is_text_node($x) };

    method element($name, @attrs, @children) {
        @children
          ??  $.element_open($name, @attrs)
              ~ $.visit(@children)
              ~ $.element_close($name)
          !!  $.element_empty($name, @attrs);
    }

    method element_open($name, @attrs) {
        sprintf '<%s%s>', $name, $.element_attrs(@attrs);
    }

    method element_close($name) {
        "</$name>";
    }

    method element_empty($name, @attrs) {
        sprintf '<%s%s />', $name, $.element_attrs(@attrs);
    }

    method element_attrs(@attrs) {<commit_msg>check for Positional rather than Array<commit_after>use v6;

class SVG {

    method serialize($tree?, *%named) {
        my $t;
        my $err = "Please pass exactly one argument to SVG.serialize";
        if defined($tree) {
            die $err unless %named.pairs == 0;
            $t = $tree;
        } else {
            die $err unless %named.pairs == 1;
            $t = %named.pairs.[0];
        }
        die 'The XML tree must have a single root node'
            unless 1 == $t.elems && $.is_element($t);
        $.visit($t.list);
    }

    method is_attribute($x) { $x ~~ Pair && $x.value !~~ Positional };
    method is_element($x)   { $x ~~ Pair && $x.value ~~ Positional };
    method is_text_node($x) { $x ~~ Str };
    method is_node($x)      { $.is_element($x) || $.is_text_node($x) };

    method element($name, @attrs, @children) {
        @children
          ??  $.element_open($name, @attrs)
              ~ $.visit(@children)
              ~ $.element_close($name)
          !!  $.element_empty($name, @attrs);
    }

    method element_open($name, @attrs) {
        sprintf '<%s%s>', $name, $.element_attrs(@attrs);
    }

    method element_close($name) {
        "</$name>";
    }

    method element_empty($name, @attrs) {
        sprintf '<%s%s />', $name, $.element_attrs(@attrs);
    }

    method element_attrs(@attrs) {
{'fraction_non_alphanumeric': 0.1750841750841751, 'fraction_numerical': 0.0037411148522259632, 'mean_word_length': 2.0386363636363636, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4953871', 'n_tokens_mistral': 879, 'n_tokens_neox': 868, 'n_words': 205}