blib/lib/ELF/Extract/Sections/Section.pm

filter: Statementstmt 59.7% 43 / 72 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 12 / 16 Podpod 100% 4 / 4 totaltotal 55.6% 59 / 106 CC 8 SCAR 23.7
CC
8
Cov
50%
write_to
30.0
compare
20.0
to_string
2.0
CRAP 10.7
↑ Summary lib/ELF/Extract/Sections/Scanner/Objdump.pm »
1 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package ELF::Extract::Sections::Section;
6  
7 # ABSTRACT: An Objective reference to a section in an ELF file.
8  
9 3 our $VERSION = '1.001004'; # TRIAL
10  
11 3 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use MooseX::Has::Sugar 0.0300;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use MooseX::Types::Moose ( ':all', );
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use ELF::Extract::Sections::Meta::Types ( ':all', );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use MooseX::Types::Path::Tiny ( 'File', );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use MooseX::Params::Validate (qw( validated_list ));
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use overload '""' => \&to_string;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24  
25  
26  
27  
28  
29  
30 3 has source => ( isa => File, ro, required, coerce, );
31  
32  
33  
34  
35  
36  
37  
38 3 has name => ( isa => Str, ro, required );
39  
40  
41  
42  
43  
44  
45  
46 3 has offset => ( isa => Int, ro, required );
47  
48  
49  
50  
51  
52  
53  
54 3 has size => ( isa => Int, ro, required );
55  
56 3 __PACKAGE__->meta->make_immutable;
57 3 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77 0 ▶sub to_string {
Subroutine to_string: not called CC=1 SCAR=6.9
Pod documented
78 0 my ( $self, ) = @_;
79 0 return sprintf
80 q{[ Section %s of size %s in %s @ %x to %x ]},
81 $self->name, $self->size, $self->source, $self->offset,
82 $self->offset + $self->size,
83 ;
84 }
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108 0 ▶sub compare {
Subroutine compare: not called CC=4 SCAR=30.0
Pod documented
109 0 my ( $self, $other, $field ) = validated_list(
110 \@_,
111 other => { isa => class_type('ELF::Extract::Sections::Section') },
112 field => { isa => FilterField, },
113 );
114 0 ▶ if ( 'name' eq $field ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("name" eq $field) 0 0 0
115 0 return ( $self->name cmp $other->name );
116 }
117 0 ▶ if ( 'offset' eq $field ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("offset" eq $field) 0 0 0
118 0 return ( $self->offset <=> $other->offset );
119 }
120 0 ▶ if ( 'size' eq $field ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("size" eq $field) 0 0 0
121 0 return ( $self->size <=> $other->size );
122 }
123 0 return;
124 }
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142 0 ▶sub write_to {
Subroutine write_to: not called CC=5 SCAR=34.0
Pod documented
143 0 my ( $self, $file ) = validated_list(
144 \@_, #
145 file => { isa => File, optional => 0, coerce => 1 },
146 );
147 0 my $fh = $self->source->openr;
148 0 seek $fh, $self->offset, 0;
149 0 my $output = $file->openw;
150 0 my $chunksize = 1024;
151 0 my $bytes_left = $self->size;
152 0 ▶ my $chunk = ( $bytes_left < $chunksize ) ? $bytes_left : $chunksize;
Branch: 1 branch
BranchTrueFalseTotal
$bytes_left < $chunksize ? : 0 0 0
153 0 ▶ while ( read $fh, my $buffer, $chunk ) {
Branch: 1 branch
BranchTrueFalseTotal
if (read $fh, my $buffer, $chunk) 0 0 0
154 0 ▶ print {$output} $buffer or Carp::croak("Write to $file failed");
Branch: 1 branch
BranchTrueFalseTotal
print {$output;} $buffer or Carp::croak("Write to $file failed") 0 0 0
155 0 $bytes_left -= $chunksize;
156 0 ▶ $chunk = ( $bytes_left < $chunksize ) ? $bytes_left : $chunksize;
Branch: 1 branch
BranchTrueFalseTotal
$bytes_left < $chunksize ? : 0 0 0
157 }
158 0 return 1;
159 }
160  
161  
162  
163  
164  
165  
166  
167  
168  
169 0 ▶sub contents {
Subroutine contents: not called CC=1 SCAR=6.9
Pod documented
170 0 my ($self) = @_;
171 0 my $fh = $self->source->openr;
172 0 seek $fh, $self->offset, 0;
173 0 my $b;
174 0 read $fh, $b, $self->size;
175 0 return $b;
176 }
177  
178 3 1;
179  
180 __END__
↑ Summary lib/ELF/Extract/Sections/Scanner/Objdump.pm »