Skip to content

Instantly share code, notes, and snippets.

@snarkyboojum
Created June 15, 2010 03:00
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 snarkyboojum/438641 to your computer and use it in GitHub Desktop.
Save snarkyboojum/438641 to your computer and use it in GitHub Desktop.
class MIME::Base64 {
# load the MIME Base64 Parrot library to do all the hard work for us
pir::load_bytecode('MIME/Base64.pbc');
method encode_base64(Str $str) {
my $encoded-str = Q:PIR {
.local pmc encode
encode = get_root_global ['parrot'; 'MIME'], 'encode_base64'
$P0 = find_lex '$str'
%r = encode($P0)
};
return $encoded-str;
}
method decode_base64(Str $str) {
my $decoded-str = Q:PIR {
.local pmc decode
decode = get_root_global ['parrot'; 'MIME'], 'decode_base64'
$P0 = find_lex '$str'
%r = decode($P0)
};
return $decoded-str;
}
}
my MIME::Base64 $mime .= new;
say $mime.encode_base64("Perl6");
# end code
Running this gives me:
$ perl6 Base64.pm6
Null PMC access in invoke()
in 'MIME::Base64::encode_base64' at line 7:Base64.pm6
in main program body at line 30:Base64.pm6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment