feat: implement Data::UUID in Java using java.util.UUID#509
Merged
Conversation
Adds a Java XS implementation for the Data::UUID CPAN module under
org.perlonjava.runtime.perlmodule.DataUUID, allowing `jcpan -t Data::UUID`
to install and run its test suite (Files=7, Tests=32, all pass).
Key points:
- Uses java.util.UUID.randomUUID() for create() (v4 random) and
MessageDigest MD5 + RFC 4122 §4.3 bit-twiddling for create_from_name()
(v3 name-based). Java's UUID.nameUUIDFromBytes does the same thing but
we build the bytes manually for clarity.
- Registers full method set: new, create{,_bin,_str,_hex,_b64},
create_from_name{,_bin,_str,_hex,_b64}, to_{string,hexstring,b64string},
from_{string,hexstring,b64string}, compare.
- Registers NameSpace_{DNS,URL,OID,X500} as constant methods matching the
RFC 4122 namespace UUIDs; the CPAN .pm file's @export wiring handles
importing them into the caller.
- Binary representation is 16-byte big-endian (RFC 4122 canonical form).
Self-consistent with to_/from_ conversions. Differs from the CPAN XS
module's host-byte-order binary on little-endian platforms, but that
binary format is not portable across platforms either.
- checkSelf() enforces that methods are called on a blessed Data::UUID
reference, matching the XS typemap behaviour that segv.t relies on.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Copies basic.t, from-name-collisions.t, leaky_dollar_bang.t and segv.t from the CPAN Data-UUID-1.227 distribution into src/test/resources/module/Data-UUID/t/ so they run as part of 'make test-bundled-modules'. All 4 tests pass against the new Java implementation. Skipped upstream tests: pod.t and pod-coverage.t (require AUTHOR_TESTING) and threads.t (PerlOnJava has no ithreads). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a Java XS implementation for the CPAN
Data::UUIDmodule underorg.perlonjava.runtime.perlmodule.DataUUID, backed byjava.util.UUIDandjava.security.MessageDigest(MD5).Before this change,
./jcpan -t Data::UUIDwould install the.pmfile but every test failed atuse Data::UUID;with "Can't load loadable object for module Data::UUID: no Java XS implementation available" (Data::UUID ships no pure-Perl fallback).After this change, the full CPAN test suite passes:
Implementation notes
create()usesUUID.randomUUID()(v4). The CPAN XS implementation produces v1 time-based UUIDs, but no test relies on the specific version — they only require uniqueness and round-tripping, both of which v4 satisfies.create_from_name()implements RFC 4122 §4.3 directly:MD5(namespace_bytes || name_bytes), then sets version=3 and the RFC 4122 variant bits.NameSpace_{DNS,URL,OID,X500}registered as constant methods returning 16-byte binary namespace UUIDs. The CPANUUID.pm's@EXPORThandles importing them at the call site.checkSelf()enforces that instance methods are called on a blessedData::UUIDreference, matching the XS typemap behaviour thatt/segv.texercises (Data::UUID->createmust die with "self is not of type Data::UUID").Test plan
jcpan -t Data::UUID→ all tests pass (32/32)make→ all unit tests pass, no regressionscreate→to_string→from_string→compare== 0Data::UUID->create(class method) dies with expected messageRelated design doc:
dev/modules/xs_fallback.md.Generated with Devin