PJVM/Class/ConstantPool.pm

filter: Statementstmt 100% 39 / 39 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 89.8% 53 / 59 CC 6 SCAR 10.4
CC
6
Cov
94%
new_from_io
5.0
length
2.0
BEGIN
1.0
CRAP 2.8
« PJVM/ClassLoader.pm ↑ Summary PJVM/Class/Attribute/Code.pm »
1 package PJVM::Class::ConstantPool;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use PJVM::Class::ConstantPool::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 CONSTANT_Class => 7,
10 CONSTANT_Fieldref => 9,
11 CONSTANT_Methodref => 10,
12 CONSTANT_InterfaceMethodref => 11,
13 CONSTANT_String => 8,
14 CONSTANT_Integer => 3,
15 CONSTANT_Float => 4,
16 CONSTANT_Long => 5,
17 CONSTANT_Double => 6,
18 CONSTANT_NameAndType => 12,
19 CONSTANT_Utf8 => 1,
20 4 };
21  
22 {
23 # Don't use fat comma (=>) here because we want to key to refer to a constant
24 4 my %constant_readers = (
25 CONSTANT_Class, "PJVM::Class::ConstantPool::Class",
26 CONSTANT_Fieldref, "PJVM::Class::ConstantPool::FieldRef",
27 CONSTANT_Methodref, "PJVM::Class::ConstantPool::MethodRef",
28 CONSTANT_InterfaceMethodref, "PJVM::Class::ConstantPool::InterfaceMethodRef",
29 CONSTANT_String, "PJVM::Class::ConstantPool::String",
30 CONSTANT_Integer, "PJVM::Class::ConstantPool::Integer",
31 CONSTANT_Float, "PJVM::Class::ConstantPool::Float",
32 CONSTANT_Long, "PJVM::Class::ConstantPool::Long",
33 CONSTANT_Double, "PJVM::Class::ConstantPool::Double",
34 CONSTANT_NameAndType, "PJVM::Class::ConstantPool::NameAndType",
35 CONSTANT_Utf8, "PJVM::Class::ConstantPool::Utf8",
36 );
37  
38 4 ▶ sub new_from_io {
Subroutine new_from_io: called CC=5 SCAR=16.1
Pod undocumented
39 4 my ($pkg, $io) = @_;
40
41 4 my $buff;
42 4 read $io, $buff, 2;
43 4 my $count = unpack("n", $buff) - 1;
44  
45 4 my $constants = [];
46 4 ▶ if ($count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count) 4 0 4
47 4 my $ix = 1;
48 4 my $tag;
49 4 ▶ while ($count--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count--) 96 4 100
50 96 read $io, $buff, 1;
51 96 my $tag = unpack("C", $buff);
52 96 ▶ die "Don't know how to read tag '${tag}'" unless exists $constant_readers{$tag};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $constant_readers{$tag} 0 96 96
53
54 96 my $constant = $constant_readers{$tag}->new_from_io($tag, $io);
55 96 $constants->[$ix++] = $constant;
56 96 ▶ if ($constant->isa("PJVM::Class::ConstantPool::Extended")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($constant->isa("PJVM::Class::ConstantPool::Extended")) 4 92 96
57 4 $constants->[$ix++] = $constant;
58 4 $count--;
59 }
60 }
61 }
62
63 4 my $self = bless $constants, $pkg;
64 4 return $self;
65 }
66 }
67  
68 4 ▶sub length {
Subroutine length: called CC=2 SCAR=7.0
Pod undocumented
69 1 my $self = shift;
70 1 my $length = scalar @$self;
71 1 ▶ return $length ? $length - 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$length ? : 1 0 1
72 }
73  
74 55 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
75 55 my ($self, $ix) = @_;
76 55 return $self->[$ix];
77 }
78  
79 4 1;
80 __END__
« PJVM/ClassLoader.pm ↑ Summary PJVM/Class/Attribute/Code.pm »