File Coverage

blib/lib/PJVM/Class/Field.pm
Criterion Covered Total %
statement 30 32 93.7
branch 1 2 50.0
condition n/a
subroutine 8 8 100.0
pod 0 3 0.0
total 39 45 86.6


line stmt bran cond sub pod time code
1             package PJVM::Class::Field;
2              
3 3     3   51 use strict;
  3         6  
  3         129  
4 3     3   17 use warnings;
  3         7  
  3         171  
5              
6 3     3   18 use Scalar::Util qw(weaken);
  3         5  
  3         401  
7              
8 3     3   2054 use PJVM::Class::Attribute;
  3         9  
  3         110  
9              
10 3         46 use Object::Tiny qw(
11             access_flags
12             name_index
13             descriptor_index
14             attributes
15             parent_class
16 3     3   17 );
  3         5  
17              
18             sub new_from_io {
19 9     9 0 16 my ($pkg, $io, $cp, $parent_class) = @_;
20            
21 9         18 my $buff;
22              
23 9         17 read $io, $buff, 8;
24              
25 9         30 my ($access_flags, $name_index, $descriptor_index, $attributes_count) = unpack("nnnn", $buff);
26            
27             # Read attributes
28 9         14 my @attributes;
29 9 50       48 if ($attributes_count) {
30 0         0 while ($attributes_count--) {
31 0         0 push @attributes, PJVM::Class::Attribute->new_from_io($io, $cp);
32             }
33             }
34            
35 9         43 my $self = $pkg->new(
36             access_flags => $access_flags,
37             name_index => $name_index,
38             descriptor_index => $descriptor_index,
39             attributes => \@attributes,
40             parent_class => $parent_class,
41             );
42            
43 9         273 weaken $self->parent_class;
44            
45 9         82 return $self;
46             }
47              
48             sub name {
49 3     3 0 743 my $self = shift;
50 3         87 my $name = $self->parent_class->constant_pool->get($self->name_index);
51 3         74 return $name->value;
52             }
53              
54             sub signature {
55 9     9 0 1642 my $self = shift;
56 9         212 my $signature = $self->parent_class->constant_pool->get($self->descriptor_index);
57 9         293 return $signature->value;
58             }
59              
60             1;
61             __END__