File Coverage

blib/lib/PJVM/Class/ConstantPool/Types.pm
Criterion Covered Total %
statement 61 69 88.4
branch n/a
condition n/a
subroutine 14 16 87.5
pod n/a
total 75 85 88.2


line stmt bran cond sub pod time code
1 4     4   20 use strict;
  4         8  
  4         134  
2 4     4   20 use warnings;
  4         6  
  4         171  
3              
4             package PJVM::Class::ConstantPool::Base;
5              
6 4         20 use Object::Tiny qw(
7             tag
8 4     4   3972 );
  4         1404  
9              
10             sub new_from_io {
11 0     0   0 my $pkg = shift;
12 0         0 die "$pkg does not implement new_from_io";
13             }
14              
15             package PJVM::Class::ConstantPool::Extended;
16             our @ISA = qw(PJVM::Class::ConstantPool::Base);
17              
18             package PJVM::Class::ConstantPool::Class;
19             our @ISA = qw(PJVM::Class::ConstantPool::Base);
20              
21 4         18 use Object::Tiny qw(
22             name_index
23 4     4   1362 );
  4         7  
24              
25             sub new_from_io {
26 12     12   24 my ($pkg, $tag, $io) = @_;
27            
28 12         18 my $buff;
29 12         20 read $io, $buff, 2;
30 12         23 my ($name_index) = unpack("n", $buff);
31            
32 12         61 my $self = $pkg->new(
33             tag => $tag,
34             name_index => $name_index,
35             );
36            
37 12         90 return $self;
38             }
39              
40             package PJVM::Class::ConstantPool::Long;
41             our @ISA = qw(PJVM::Class::ConstantPool::Extended);
42              
43 4         17 use Object::Tiny qw(
44             value
45 4     4   1158 );
  4         8  
46              
47             sub new_from_io {
48 4     4   11 my ($pkg, $tag, $io) = @_;
49            
50 4         11 my $buff;
51 4         13 read $io, $buff, 8;
52 4         13 my ($high, $low) = unpack("NN", $buff);
53            
54 4         23 my $value = ($high * (2**32)) + $low;
55            
56 4         42 my $self = $pkg->new(
57             tag => $tag,
58             value => $value,
59             );
60            
61 4         35 return $self;
62             }
63              
64             package PJVM::Class::ConstantPool::Ref;
65             our @isa = qw(PJVM::Class::ConstantPool::Base);
66              
67 4         19 use Object::Tiny qw(
68             tag
69             class_index
70             name_and_type_index
71 4     4   1316 );
  4         8  
72              
73             sub new_from_io {
74 4     4   17 my ($pkg, $tag, $io) = @_;
75            
76 4         17 my $buff;
77 4         12 read $io, $buff, 4;
78 4         12 my ($class_index, $name_and_type_index) = unpack("nn", $buff);
79              
80 4         47 my $self = $pkg->new(
81             tag => $tag,
82             class_index => $class_index,
83             name_and_type_index => $name_and_type_index,
84             );
85            
86 4         54 return $self;
87             }
88              
89             package PJVM::Class::ConstantPool::FieldRef;
90             our @ISA = qw(PJVM::Class::ConstantPool::Ref);
91              
92             package PJVM::Class::ConstantPool::MethodRef;
93             our @ISA = qw(PJVM::Class::ConstantPool::Ref);
94              
95             package PJVM::Class::ConstantPool::InterfaceMethodRef;
96             our @ISA = qw(PJVM::Class::ConstantPool::Ref);
97              
98             package PJVM::Class::ConstantPool::NameAndType;
99             our @ISA = qw(PJVM::Class::ConstantPool::Base);
100              
101 4         37 use Object::Tiny qw(
102             name_index
103             descriptor_index
104 4     4   1645 );
  4         8  
105              
106             sub new_from_io {
107 4     4   12 my ($pkg, $tag, $io) = @_;
108            
109 4         7 my $buff;
110 4         19 read $io, $buff, 4;
111 4         11 my ($name_index, $descriptor_index) = unpack("nn", $buff);
112              
113 4         48 my $self = $pkg->new(
114             tag => $tag,
115             name_index => $name_index,
116             descriptor_index => $descriptor_index,
117             );
118            
119 4         39 return $self;
120             }
121              
122             package PJVM::Class::ConstantPool::String;
123             our @ISA = qw(PJVM::Class::ConstantPool::Base);
124              
125 4         17 use Object::Tiny qw(
126             string_index
127 4     4   1361 );
  4         14  
128              
129             sub new_from_io {
130 0     0   0 my ($pkg, $tag, $io) = @_;
131            
132 0         0 my $buff;
133 0         0 read $io, $buff, 2;
134 0         0 my ($string_index) = unpack("n", $buff);
135              
136 0         0 my $self = $pkg->new(
137             tag => $tag,
138             string_index => $string_index,
139             );
140            
141 0         0 return $self;
142             }
143              
144             package PJVM::Class::ConstantPool::Utf8;
145             our @ISA = qw(PJVM::Class::ConstantPool::Base);
146              
147 4         15 use Object::Tiny qw(
148             value
149 4     4   1002 );
  4         9  
150              
151             sub new_from_io {
152 72     72   113 my ($pkg, $tag, $io) = @_;
153            
154 72         74 my $buff;
155 72         99 read $io, $buff, 2;
156 72         121 my ($length) = unpack("n", $buff);
157            
158 72         101 read $io, $buff, $length;
159 72         206 my $str = $buff;
160 72         127 utf8::upgrade($str);
161            
162 72         212 my $self = $pkg->new(
163             tag => $tag,
164             value => $str,
165             );
166            
167 72         556 return $self;
168             }
169              
170             1;
171             __END__