The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
module CGI::Util-0.0.1;

use v6;

sub make_attribute(%attrs, Bool $escape = 0) is export {
    my @return;
    
    for %attrs.keys -> $key {
        my $copy = lc $key;
        
        $copy ~~ s:P5:g/_/-/;
        
        my $value = ($escape) ?? simple_escape(%attrs{$key}) !! %attrs{$key};
        
        push @return, (%attrs{$key}.defined) ?? qq/$copy="$value"/ !! qq/$copy/;
    }
    
    return @return;
}

sub simple_escape (Str $string is copy) returns Str {
    $string ~~ s:P5:g/&/&/;
    $string ~~ s:P5:g/</&lt;/;
    $string ~~ s:P5:g/>/&gt;/;
    $string ~~ s:P5:g/"/&quot;/;
    
    return $string;
}

1;