Skip to content

Instantly share code, notes, and snippets.

@jonathanstowe
Last active January 8, 2016 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanstowe/f3513b8b75a3868c7f58 to your computer and use it in GitHub Desktop.
Save jonathanstowe/f3513b8b75a3868c7f58 to your computer and use it in GitHub Desktop.
class XMLWriter {
has $!in = 0;
method FALLBACK($name, *@c, *%attrs) {
(temp $!in)++;
my Str $attrs = (%attrs.keys > 0 ?? ' ' !! '') ~ %attrs.kv.map( -> $k, $v { "$k=\"$v\"" }).join(' ');
"<$name$attrs>\n" ~ @c>>.indent($!in).join("\n") ~ (+@c ?? "\n" !! "") ~ "</$name>"
}
}
my $x = XMLWriter.new;
say $x.foo($x.bar($x.baz("stuff")), zub => "flurble", bumble => "rarr");
# vim: expandtab shiftwidth=4 ft=perl6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment