File Coverage

blib/lib/PJVM/Class/Attribute/Code.pm
Criterion Covered Total %
statement 29 32 90.6
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 34 39 87.1


line stmt bran cond sub pod time code
1             package PJVM::Class::Attribute::Code;
2              
3 3     3   16 use strict;
  3         4  
  3         102  
4 3     3   13 use warnings;
  3         6  
  3         101  
5              
6 3         28 use Object::Tiny qw(
7             max_stack
8             max_locals
9             code
10             exceptions_table
11 3     3   15 );
  3         19  
12              
13             sub new_from_io {
14 9     9 0 23 my ($pkg, $io, $cp) = @_;
15            
16 9         11 my $buff;
17            
18             # Stack stuff
19 9         16 read $io, $buff, 4;
20 9         20 my ($max_stack, $max_locals) = unpack("nn", $buff);
21            
22             # Number of operations
23 9         108 read $io, $buff, 4;
24 9         16 my $op_count = unpack("N", $buff);
25            
26             # Load code
27 9         17 read $io, $buff, $op_count;
28 9         11 my $code = $buff;
29            
30             # Exceptions stuff
31 9         15 read $io, $buff, 2;
32 9         15 my $ex_table_count = unpack("n", $buff);
33 9         18 my @exceptions_table;
34 9         27 while ($ex_table_count--) {
35 0         0 read $io, $buff, 8;
36 0         0 my ($start_pc, $end_pc, $handler_pc, $catch_type) = unpack("nnnn", $buff);
37 0         0 push @exceptions_table, [$start_pc, $end_pc, $handler_pc, $catch_type];
38             }
39            
40             # Attributes
41 9         14 read $io, $buff, 2;
42 9         15 my $attributes_count = unpack("n", $buff);
43            
44             # Read attributes
45 9         13 my @attributes;
46 9 50       28 if ($attributes_count) {
47 9         21 while ($attributes_count--) {
48 9         52 push @attributes, PJVM::Class::Attribute->new_from_io($io, $cp);
49             }
50             }
51            
52 9         50 my $self = $pkg->new(
53             max_stack => $max_stack,
54             max_locals => $max_locals,
55             code => $code,
56             exceptions_table => \@exceptions_table,
57             attributes => \@attributes,
58             );
59            
60 9         137 return $self;
61             }
62              
63             1;
64             __END__