Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First working version, on r45822

  • Loading branch information...
commit 6ba01feccccad5ea88d92a06178f732228cec167 0 parents
@cosimo authored
2  .gitignore
@@ -0,0 +1,2 @@
+Makefile
+*.pir
21 README
@@ -0,0 +1,21 @@
+Perl6 Digest::MD5 module
+========================
+
+An interface-compatible port of Perl5 Digest::MD5 to Perl6.
+
+Cosimo Streppone (cosimo@cpan.org)
+
+
+Repository
+==========
+
+ <http://github.com/cosimo/perl6-digest-md5>
+
+
+Current status (2010-06-10)
+===========================
+
+After a bit of fiddling, perl6-digest-md5 runs just fine
+on parrot r45822, but it fails on newer parrot/rakudo versions
+with an obscure "failed find_method 'signature'" message.
+
5 TODO
@@ -0,0 +1,5 @@
+[ ] Complete the full p5 Digest::MD5 interface
+[ ] Import some more test cases from the p5 test suite
+[ ] Fix the find_method 'signature' failure message
+ on newer parrot/rakudo combinations
+
30 lib/Digest/MD5.pm
@@ -0,0 +1,30 @@
+#
+# Digest::MD5 Perl6 module
+#
+
+class Digest::MD5 {
+
+ multi method md5_hex (Str $message) {
+
+ pir::load_bytecode('Digest/MD5.pbc');
+
+ my $md5_sum = Q:PIR {
+ load_bytecode 'Digest/MD5.pbc'
+ .local pmc md5sum, md5_sum_get
+ md5sum = get_root_global ['parrot'; 'Digest'], '_md5sum'
+ $P0 = find_lex '$message'
+ $P1 = md5sum($P0)
+ md5_sum_get = get_root_global ['parrot'; 'Digest'], '_md5_hex'
+ %r = md5_sum_get($P1)
+ };
+
+ return $md5_sum;
+ }
+
+ multi method md5_hex (@message) {
+ my Str $message = @message.join('');
+ return Digest::MD5.md5_hex($message);
+ }
+
+}
+
13 old-tests/test.p6
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+Q:PIR {
+ load_bytecode 'Digest/MD5.pbc'
+ .local pmc md5sum, md5print
+ md5sum = get_root_global ['parrot'; 'Digest'], '_md5sum'
+ $P0 = md5sum('foo')
+ md5print = get_root_global ['parrot'; 'Digest'], '_md5_print'
+ md5print($P0)
+}
+
19 old-tests/test2.p6
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+sub mysub (Str $text) {
+ Q:PIR {
+ load_bytecode 'Digest/MD5.pbc'
+ .local pmc md5sum, md5print
+ md5sum = get_root_global ['parrot'; 'Digest'], '_md5sum'
+ $P0 = find_lex '$text'
+ $P1 = md5sum($P0)
+ md5print = get_root_global ['parrot'; 'Digest'], '_md5_print'
+ md5print($P1)
+ }
+}
+
+mysub('foo');
+
+
19 old-tests/test3.p6
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+sub mysub (Str $text) {
+ my $md5_sum = Q:PIR {
+ load_bytecode 'Digest/MD5.pbc'
+ .local pmc md5sum, md5print
+ md5sum = get_root_global ['parrot'; 'Digest'], '_md5sum'
+ $P0 = find_lex '$text'
+ %r = md5sum($P0)
+ };
+ say $md5_sum;
+ return $md5_sum;
+}
+
+say mysub('foo');
+
+
17 old-tests/test4.p6
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl6
+
+sub md5_hex (Str $message) {
+ my $md5_sum = Q:PIR {
+ load_bytecode 'Digest/MD5.pbc'
+ .local pmc md5sum, md5_sum_get
+ md5sum = get_root_global ['parrot'; 'Digest'], '_md5sum'
+ $P0 = find_lex '$message'
+ $P1 = md5sum($P0)
+ md5_sum_get = get_root_global ['parrot'; 'Digest'], '_md5_hex'
+ %r = md5_sum_get($P1)
+ };
+ return $md5_sum;
+}
+
+say md5_hex('foo');
+
7 t/0-load-module.t
@@ -0,0 +1,7 @@
+use Test;
+use Digest::MD5;
+
+ok(1, 'Module loaded');
+
+done_testing;
+
24 t/perl5-compat.t
@@ -0,0 +1,24 @@
+#
+# Test compability with Perl5 Digest::MD5
+#
+
+use Test;
+use Digest::MD5;
+
+my @cases = (
+ "Hello World" , 'b10a8db164e0754105b7a99be72e3fe5',
+ "Hello World\n", 'e59ff97941044f85df5297e1c302d260',
+ ["a", "b"], '187ef4436122d1cc2f40dc2b92f0eba0',
+);
+
+for @cases -> $values, $md5 {
+
+ is(
+ Digest::MD5.md5_hex($values), $md5,
+ "MD5 of '$values' must be '$md5'"
+ );
+
+}
+
+done_testing;
+
Please sign in to comment.
Something went wrong with that request. Please try again.