use v6-alpha; module CGI::Util-0.0.1; sub make_attribute(%attrs, Bool $escape = 0) is export { gather { for %attrs.keys.sort -> $key { my $copy = lc $key; $copy ~~ s:P5:g/_/-/; my $value = ($escape) ?? simple_escape(%attrs{$key}) !! %attrs{$key}; take((%attrs{$key}.defined) ?? qq/$copy="$value"/ !! qq/$copy/); } }; } sub simple_escape (Str $string is copy) returns Str { $string ~~ s:P5:g/&/&/; $string ~~ s:P5:g//>/; $string ~~ s:P5:g/"/"/; return $string; } 1;