File Coverage

blib/lib/ELF/Writer/Section.pm
Criterion Covered Total %
statement 12 36 33.3
branch 0 26 0.0
condition 0 3 0.0
subroutine 4 14 28.5
pod 0 8 0.0
total 16 87 18.3


line stmt bran cond sub pod time code
1             package ELF::Writer::Section;
2 1     1   5 use Moo 2;
  1         17  
  1         4  
3 1     1   192 use Carp;
  1         1  
  1         39  
4 1     1   3 use ELF::Writer;
  1         1  
  1         18  
5 1     1   3 use namespace::clean;
  1         1  
  1         4  
6              
7             *VERSION= *ELF::Writer::VERSION;
8              
9             # ABSTRACT: Object representing the fields of one section in an ELF file.
10              
11              
12             has name => ( is => 'rw' );
13              
14             our (%type_to_sym, %type_from_sym);
15             ELF::Writer::_init_enum(\%type_to_sym, \%type_from_sym,
16             'null' => 0, # Ignore this section entry
17             'progbits' => 1, # Contents of section are program specific
18             'symtab' => 2, # symbol table
19             'strtab' => 3, # string table
20             'rela' => 4, # relocation table with specific addends
21             'hash' => 5, # symbol hash table
22             'dynamic' => 6, # dynamic linking information
23             'note' => 7, # various identification of file
24             'nobits' => 8, # program-specific "pointer" using offset field. has no length.
25             'rel' => 9, # relocation table without specific addends
26             'shlib' => 10, # ??
27             'dynsym' => 11, # symbol table
28             'num' => 12, # ??
29             );
30              
31             has type => ( is => 'rw', coerce => sub {
32             my $x= $type_from_sym{$_[0]};
33             defined $x? $x
34             : (int($_[0]) == $_[0])? $_[0]
35             : croak "$_[0] is not a valid 'type'"
36             });
37              
38             sub type_sym {
39 0     0 0   my $self= shift;
40 0 0         $self->type($_[0]) if @_;
41 0           my $v= $self->type;
42 0 0         $type_to_sym{$v} || $v
43             }
44              
45              
46             has flags => ( is => 'rw' );
47              
48             sub flag_write {
49 0     0 0   my ($self, $value)= @_;
50 0 0         $self->flags( $self->flags & ~1 | ($value? 1 : 0) )
    0          
51             if defined $value;
52 0           $self->flags & 1;
53             }
54              
55             sub flag_alloc {
56 0     0 0   my ($self, $value)= @_;
57 0 0         $self->flags( $self->flags & ~2 | ($value? 2 : 0) )
    0          
58             if defined $value;
59 0           $self->flags & 2;
60             }
61              
62             sub flag_execinstr {
63 0     0 0   my ($self, $value)= @_;
64 0 0         $self->flags( $self->flags & ~4 | ($value? 4 : 0) )
    0          
65             if defined $value;
66 0           $self->flags & 4;
67             }
68              
69              
70             has addr => ( is => 'rw' );
71             has offset => ( is => 'rw' );
72             has size => ( is => 'rw' );
73             has link => ( is => 'rw' );
74             has info => ( is => 'rw' );
75             has addralign => ( is => 'rw' );
76             has entsize => ( is => 'rw' );
77              
78              
79             has data => ( is => 'rw' );
80             has data_start => ( is => 'rw', default => sub { 0 } );
81              
82 0     0 0   sub data_offset { $_[0]->offset + $_[0]->data_start }
83              
84             has _index => ( is => 'rw' );
85 0     0     sub _name { "segment ".shift->_index }
86 0 0   0     sub _required_file_alignment { $_[0]->addralign || 1 }
87              
88              
89             sub BUILD {
90 0     0 0   my ($self, $params)= @_;
91             defined $params->{flag_write}
92 0 0         and $self->flag_write($params->{flag_write});
93             defined $params->{flag_alloc}
94 0 0         and $self->flag_alloc($params->{flag_alloc});
95             defined $params->{flag_execinstr}
96 0 0         and $self->flag_execinstr($params->{flag_execinstr});
97             }
98              
99             sub coerce {
100 0     0 0   my ($class, $thing)= @_;
101 0 0 0       return (ref $thing && ref($thing)->isa(__PACKAGE__))? $thing : $class->new($thing);
102             }
103              
104             sub clone {
105 0     0 0   my $self= shift;
106 0           return bless { %$self }, ref $self;
107             }
108              
109             1;
110              
111             __END__