Created
June 15, 2010 03:00
-
-
Save snarkyboojum/438641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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