Hullo. I ask the module naming gods for advice. Here is my goat.

I'm about to finish writing a module which parsers Java .class files
and reports the structure of the file by returning an object
containing all information in the file: constants, methods, actual JVM
bytecode etc. The module will eventually expose JVM bytecodes and,
well, things to make a Perl / Parrot JVM implementation possible.

The Classfile is strictly part of the JVM and not of Java, so my best
guess so far is JVM::ClassFile. I'm not a big fan of modules named
...Parser, as surely everything does that these days (that's worse
than having XML:: everything). However, JVM:: is a new namespace
(there's already Jvm though, should I use that instead?).

OK, basically, my question is: Is JVM::ClassFile ok?

Copious example excerpt from test file:

my $c = JVM::ClassFile->new("HelloWorld.class");
ok(ref($c), "Loaded HelloWorld");
ok($c->magic == 0xCAFEBABE, "Good magic");
ok($c->version eq '45.3', "Right compiler version");
ok($c->class eq 'HelloWorld', "Right class");
ok($c->superclass eq 'java/lang/Object', "Right superclass");
ok(scalar(@{$c->constant_pool}) == 29, "Full constant pool");
ok(scalar(@{$c->access_flags}) == 1, "Right number of class access flags");
ok($c->access_flags->[0] eq 'super', "Correct super class access flags");
ok(scalar(@{$c->interfaces}) == 0, "No interfaces");
ok(scalar(@{$c->fields}) == 0, "No fields");
ok(scalar(@{$c->methods}) == 2, "Right number of methods");

my $method = $c->methods->[0];
ok($method->name eq '<init>', "<init> named");
ok($method->descriptor eq '()V', "<init> descriptor");
ok(scalar(@{$method->access_flags}) == 0, "<init> has no access flags");
ok(scalar(@{$method->attributes}) == 1, "<init> has 1 attribute");
ok($method->attributes->[0]->name eq 'Code', "<init> has Code attribute");

$method = $c->methods->[1];
ok($method->name eq 'main', "main named");
ok($method->descriptor eq '([Ljava/lang/String;)V', "main descriptor");
ok(scalar(@{$method->access_flags}) == 2, "main has two access flags");
ok(scalar(grep { $_ eq 'public' } @{$method->access_flags}) == 1, "main has access 
flags public");
ok(scalar(grep { $_ eq 'static' } @{$method->access_flags}) == 1, "main has access 
flags static");
ok(scalar(@{$method->attributes}) == 1, "main has 1 attribute");
ok($method->attributes->[0]->name eq 'Code', "main has Code attribute");

ok(scalar(@{$c->attributes}) == 1, "Right number of attributes");
ok($c->attributes->[0]->name eq 'SourceFile', "SourceFile attribute present");
ok($c->attributes->[0]->value eq 'HelloWorld.java', "SourceFile attribute value 
correct");

Many thanks O holy Gods I bow to your judgement ;-), Leon
-- 
Leon Brocard.............................http://www.astray.com/
Nanoware...............................http://www.nanoware.org/

... Bad Command:(A)bort (R)etry (T)ake RAM hostage

Reply via email to