Embed/Writer.pm

filter: Statementstmt 91.7% 201 / 219 Branchbran 65.2% 77 / 118 Conditioncond 83.3% 20 / 24 MC/DCmcdc 60.0% 9 / 15 Subroutinesub 100% 19 / 19 Podpod 100% 6 / 6 totaltotal 82.7% 332 / 401 CC 70 SCAR 24.3
CC
70
Cov
83%
__output_for_new
21.8
_transfer_input
16.2
__input_for_new
11.1
CRAP 11.4
« Embed/File.pm ↑ Summary Embed.pm »
1 package Data::Embed::Writer;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use English qw< -no_match_vars >;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Data::Embed::Reader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Log::Log4perl::Tiny qw< :easy :dead_if_first >;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Data::Embed::Util qw< :constants escape >;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Fcntl qw< :seek >;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Scalar::Util qw< refaddr >;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 our $VERSION = '0.32'; # make indexer happy
13  
14 62 ▶sub __output_for_new {
Subroutine __output_for_new: called CC=21 SCAR=30.8
15 62 my $self = shift;
16 62 my $package = ref $self;
17 62 my $output = $self->{output} = $self->{args}{output};
18 62 $self->{output_same_as_input} = 0; # by default
19  
20 # The simple stuff: not present/defined, or the classical "-" string
21 62 ▶ if ((!defined($output)) || (!length($output)) || ($output eq '-')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $output && length $output or $output eq "-") 24 38 62
Condition100%6/6
not defined $output && length $output or $output eq "-"
l!l&&r!l&&!r
18638
defined $output && length $output
!ll&&!rl&&r
12644
MC/DC100%3/3
not defined $output && length $output or $output eq "-"
defined $output length $output $output eq "-"
Truth table100%4/4
not(A && B) or C
A= defined $outputB= length $outputC= $output eq "-"
ABCresult
0XX1
10X1
1111
1100
22 24 DEBUG $package, "::__output_for_new(): output to STDOUT";
23 24 ▶ open my $fh, '>&', \*STDOUT
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">&", \*STDOUT or LOGCROAK("dup(): $Data::Embed::Writer::OS_ERROR") 24 0 24
24 or LOGCROAK "dup(): $OS_ERROR";
25 24 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode(\\*STDOUT): $Data::Embed::Writer::OS_ERROR") 24 0 24
26 or LOGCROAK "binmode(\\*STDOUT): $OS_ERROR";
27 24 $self->{output_name} = '<STDOUT>';
28 24 $self->{output_fh} = $fh;
29 24 $self->{output_type} = 'filehandle';
30 24 return $self;
31 } ## end if ((!defined($output)...))
32  
33 38 my $oref = ref $output;
34 38 ▶ if (!$oref) { # filename
Branch: 1 branch
BranchTrueFalseTotal
unless ($oref) 9 29 38
35 9 DEBUG $package, '::__output:for_new(): output to a file';
36 9 $self->{output_type} = 'file';
37 9 $self->{output_name} = $output;
38  
39 # same file as input? If yes, do not clobber
40 9 ▶ if (($self->{input_type} eq 'file') && ($output eq $self->{input})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"input_type"} eq "file" and $output eq $self->{"input"}) 3 6 9
Condition100%3/3
$self->{"input_type"} eq "file" and $output eq $self->{"input"}
!ll&&!rl&&r
513
MC/DC100%2/2
$self->{"input_type"} eq "file" and $output eq $self->{"input"}
$self->{"input_type"} eq "file" $output eq $self->{"input"}
Truth table100%3/3
A and B
A= $self->{"input_type"} eq "file"B= $output eq $self->{"input"}
ABresult
0X0
100
111
41 3 ▶ open my $fh, '+<', $output
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "+<", $output or LOGCROAK("open('${output}'): $Data::Embed::Writer::OS_ERROR") 3 0 3
42 or LOGCROAK "open('$output'): $OS_ERROR";
43 3 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode('${output}'): $Data::Embed::Writer::OS_ERROR") 3 0 3
44 or LOGCROAK "binmode('$output'): $OS_ERROR";
45 3 $self->{output_fh} = $fh;
46 3 $self->{output_same_as_input} = 1;
47 3 return $self;
48 } ## end if (($self->{input_type...}))
49  
50 6 ▶ open my $fh, '>', $output
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $output or LOGCROAK("open('${output}'): $Data::Embed::Writer::OS_ERROR") 6 0 6
51 or LOGCROAK "open('$output'): $OS_ERROR";
52 6 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode('${output}'): $Data::Embed::Writer::OS_ERROR") 6 0 6
53 or LOGCROAK "binmode('$output'): $OS_ERROR";
54 6 $self->{output_fh} = $fh;
55 6 return $self;
56 } ## end if (!$oref)
57  
58 29 ▶ if ($oref eq 'SCALAR') { # reference to a scalar, similar to filename
Branch: 1 branch
BranchTrueFalseTotal
if ($oref eq "SCALAR") 22 7 29
59 22 DEBUG $package, '::__output:for_new(): output to a scalar ref';
60 22 $self->{output_type} = 'scalar-ref';
61 22 $self->{output_name} = "{$output}";
62  
63 # same file as input? If yes, do not clobber
64 22 ▶ if ( ($self->{input_type} eq 'scalar-ref')
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"input_type"} eq "scalar-ref" and builtin::refaddr($output) eq builtin::refaddr($self->{"input"})) 7 15 22
Condition100%3/3
$self->{"input_type"} eq "scalar-ref" and builtin::refaddr($output) eq builtin::refaddr($self->{"input"})
!ll&&!rl&&r
1417
MC/DC100%2/2
$self->{"input_type"} eq "scalar-ref" and builtin::refaddr($output) eq builtin::refaddr($self->{"input"})
$self->{"input_type"} eq "scalar-ref" builtin::refaddr($output) eq builtin::refaddr($self->{"input"})
Truth table100%3/3
A and B
A= $self->{"input_type"} eq "scalar-ref"B= builtin::refaddr($output) eq builtin::refaddr($self->{"input"})
ABresult
0X0
100
111
65 && (refaddr($output) eq refaddr($self->{input})))
66 {
67 7 ▶ open my $fh, '+<', $output
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "+<", $output or LOGCROAK("open('${output}'): $Data::Embed::Writer::OS_ERROR") 7 0 7
68 or LOGCROAK "open('$output'): $OS_ERROR";
69 7 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode('${output}'): $Data::Embed::Writer::OS_ERROR") 7 0 7
70 or LOGCROAK "binmode('$output'): $OS_ERROR";
71 7 $self->{output_fh} = $fh;
72 7 $self->{output_same_as_input} = 1;
73 7 return $self;
74 } ## end if (($self->{input_type...}))
75  
76 15 ▶ open my $fh, '>', $output
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $output or LOGCROAK("open('${output}'): $Data::Embed::Writer::OS_ERROR") 15 0 15
77 or LOGCROAK "open('$output'): $OS_ERROR";
78 15 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode('${output}'): $Data::Embed::Writer::OS_ERROR") 15 0 15
79 or LOGCROAK "binmode('$output'): $OS_ERROR";
80 15 $self->{output_fh} = $fh;
81 15 return $self;
82 } ## end if ($oref eq 'SCALAR')
83  
84 # Otherwise, we will have to assume that it is a filehandle
85 7 $self->{output_name} = '<HANDLE>';
86 7 $self->{output_fh} = $output;
87 7 $self->{output_type} = 'filehandle';
88 $self->{output_same_as_input} = ($self->{input_type} eq 'filehandle')
89 7 ▶ && (refaddr($output) eq refaddr($self->{input_fh}));
Condition66%2/3
$self->{'input_type'} eq 'filehandle' && builtin::refaddr($output) eq builtin::refaddr($self->{'input_fh'})
!ll&&!rl&&r
520
MC/DC0%0/2
$self->{'input_type'} eq 'filehandle' && builtin::refaddr($output) eq builtin::refaddr($self->{'input_fh'})
$self->{'input_type'} eq 'filehandle' builtin::refaddr($output) eq builtin::refaddr($self->{'input_fh'})
Truth table66%2/3
A && B
A= $self->{'input_type'} eq 'filehandle'B= builtin::refaddr($output) eq builtin::refaddr($self->{'input_fh'})
ABresult
0X0
100
111
90 7 return $self;
91 } ## end sub __output_for_new
92  
93 62 ▶sub __input_for_new {
Subroutine __input_for_new: called CC=11 SCAR=24.1
94 62 my $self = shift;
95 62 my $package = ref $self;
96 62 my $input = $self->{input} = $self->{args}{input};
97  
98 # if not defined, it just does not exist
99 62 ▶ if (!defined($input)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $input) 24 38 62
100 24 DEBUG $package, "::__input_for_new(): no input";
101 24 $self->{input_name} = '*undef*';
102 24 $self->{input_fh} = undef;
103 24 $self->{input_type} = 'undef';
104 24 return $self;
105 } ## end if (!defined($input))
106  
107 # the classical "-" string
108 38 ▶ if ($input eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($input eq "-") 7 31 38
109 7 DEBUG $package, "::__input_for_new(): input from STDIN";
110 7 ▶ open my $fh, '<&', \*STDIN
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<&", \*STDIN or LOGCROAK("dup(): $Data::Embed::Writer::OS_ERROR") 7 0 7
111 or LOGCROAK "dup(): $OS_ERROR";
112 7 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode(\\*STDIN): $Data::Embed::Writer::OS_ERROR") 7 0 7
113 or LOGCROAK "binmode(\\*STDIN): $OS_ERROR";
114 7 $self->{input_name} = '<STDIN>';
115 7 $self->{input_fh} = $fh;
116 7 $self->{input_type} = 'filehandle';
117 7 return $self;
118 } ## end if ($input eq '-')
119  
120 31 my $iref = ref $input;
121 31 ▶ if (!$iref) { # filename
Branch: 1 branch
BranchTrueFalseTotal
unless ($iref) 10 21 31
122 10 DEBUG $package, '::__input:for_new(): input from file';
123 10 ▶ open my $fh, '<', $input
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $input or LOGCROAK("open('${input}'): $Data::Embed::Writer::OS_ERROR") 10 0 10
124 or LOGCROAK "open('$input'): $OS_ERROR";
125 10 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode('${input}'): $Data::Embed::Writer::OS_ERROR") 10 0 10
126 or LOGCROAK "binmode('$input'): $OS_ERROR";
127 10 $self->{input_name} = $input;
128 10 $self->{input_fh} = $fh;
129 10 $self->{input_type} = 'file';
130 10 return $self;
131 } ## end if (!$iref)
132  
133 21 ▶ if ($iref eq 'SCALAR') { # reference to a scalar, similar to filename
Branch: 1 branch
BranchTrueFalseTotal
if ($iref eq "SCALAR") 14 7 21
134 14 DEBUG $package, '::__input:for_new(): input from a scalar ref';
135 14 ▶ open my $fh, '<', $input
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $input or LOGCROAK("open('${input}'): $Data::Embed::Writer::OS_ERROR") 14 0 14
136 or LOGCROAK "open('$input'): $OS_ERROR";
137 14 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode('${input}'): $Data::Embed::Writer::OS_ERROR") 14 0 14
138 or LOGCROAK "binmode('$input'): $OS_ERROR";
139 14 $self->{input_name} = "{$input}";
140 14 $self->{input_fh} = $fh;
141 14 $self->{input_type} = 'scalar-ref';
142 14 return $self;
143 } ## end if ($iref eq 'SCALAR')
144  
145 # Otherwise, we will have to assume that it is a filehandle
146 7 $self->{input_name} = '<HANDLE>';
147 7 $self->{input_fh} = $input;
148 7 $self->{input_type} = 'filehandle';
149 7 return $self;
150 } ## end sub __input_for_new
151  
152 62 ▶sub _transfer_input {
Subroutine _transfer_input: called CC=10 SCAR=27.9
153 62 my $self = shift;
154 62 ▶ if (!$self->{input_transferred}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"input_transferred"}) 62 0 62
155  
156 # if there is an input, transfer to the output if it is the case
157 62 ▶ if ($self->{input_fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"input_fh"}) 38 24 62
158 38 ▶ if ($self->{output_same_as_input})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'output_same_as_input'}) { } 10 28 38
159 { # don't copy, assume seekable input
160 10 my $reader = Data::Embed::Reader->new($self->{input_fh});
161 10 my $ifile = $reader->_index(); # private method called
162 10 my @index = $ifile->contents();
163 10 shift @index; # eliminate STARTER
164 10 pop @index; # eliminate TERMINATOR
165 10 $self->{index} = \@index; # initialize previous index
166 # put out handle in right position
167 10 seek $self->{output_fh}, $ifile->{offset}, SEEK_SET;
168 } ## end if ($self->{output_same_as_input...})
169 else {
170 28 my $starter = STARTER;
171 28 my $terminator = TERMINATOR;
172 28 my (@index, $index_completed);
173 28 my $ifh = $self->{input_fh};
174 28 my $ofh = $self->{output_fh};
175 INPUT:
176 28 ▶ while (<$ifh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $ifh)) 28 28 56
177 28 ▶ if (!@index) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @index) { } 28 0 28
elsif (not $index_completed) { } 0 0 0
178 28 ▶ if ($_ eq $starter) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $starter) { } 0 28 28
179 0 push @index, $_;
180 0 next INPUT;
181 }
182 else {
183 28 print {$ofh} $_;
184 }
185 } ## end if (!@index)
186 elsif (!$index_completed) { # accumulating index
187 0 ▶ if (m{\A \s* (\d+) \s+ (\S*) \s*\z}mxs) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\A \s* (\d+) \s+ (\S*) \s*\z/msx) { } 0 0 0
elsif ($_ eq $terminator) { } 0 0 0
188 0 push @index, $_;
189 }
190 elsif ($_ eq $terminator) {
191 0 push @index, $_;
192 0 $index_completed = 1;
193 }
194 else { # not a valid index, flush accumulated lines
195 0 print {$ofh} @index;
196 0 @index = ();
197 0 $index_completed = undef; # paranoid
198 }
199 } ## end elsif (!$index_completed)
200 else
201 { # accumulating and index completed, but other stuff...
202 0 print {$ofh} @index; # flush and reset
203 0 @index = ();
204 0 $index_completed = undef;
205 } ## end else [ if (!@index) ]
206 } ## end INPUT: while (<$ifh>)
207 28 shift @index; # eliminate STARTER
208 28 pop @index; # eliminate TERMINATOR
209 28 $self->{index} = \@index; # initialize previous index
210 } ## end else [ if ($self->{output_same_as_input...})]
211 } ## end if ($self->{input_fh})
212 62 $self->{input_transferred} = 1;
213 } ## end if (!$self->{input_transferred...})
214 62 return $self;
215 } ## end sub _transfer_input
216  
217 62 ▶sub new {
Subroutine new: called CC=5 SCAR=17.1
Pod documented
218 62 my $package = shift;
219 0 ▶ my %args = (scalar(@_) && ref($_[0])) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ && ref $_[0] ? : 0 62 62
Condition66%2/3
scalar @_ and ref $_[0]
!ll&&!rl&&r
1610
MC/DC0%0/2
scalar @_ and ref $_[0]
scalar @_ ref $_[0]
Truth table66%2/3
A and B
A= scalar @_B= ref $_[0]
ABresult
0X0
100
111
220 62 ▶ $args{transfer_input} = 1 unless exists $args{transfer_input};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"transfer_input"} 62 0 62
221  
222 # Undocumented, keep additional parameters around...
223 62 my $self = bless {args => \%args}, $package;
224  
225 # first of all, resolve the input
226 62 $self->__input_for_new();
227  
228 # then the output (might depend on the input)
229 62 $self->__output_for_new();
230  
231 62 ▶ $self->_transfer_input() if $args{transfer_input};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"transfer_input"} 62 0 62
232  
233 62 return $self;
234 } ## end sub new
235  
236 106 ▶sub add {
Subroutine add: called CC=5 SCAR=17.5
Pod documented
237 106 my $self = shift;
238 0 ▶ my %args = (scalar(@_) && ref($_[0])) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ && ref $_[0] ? : 0 106 106
Condition33%1/3
scalar @_ and ref $_[0]
!ll&&!rl&&r
01060
MC/DC0%0/2
scalar @_ and ref $_[0]
scalar @_ ref $_[0]
Truth table33%1/3
A and B
A= scalar @_B= ref $_[0]
ABresult
0X0
100
111
239  
240 $self->_add($_)
241 106 ▶ for (defined($args{inputs}) ? @{$args{inputs}} : (\%args));
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'inputs'} ? : 7 99 106
242  
243 106 return $self;
244 } ## end sub add
245  
246 112 ▶sub _add {
Subroutine _add: called CC=10 SCAR=23.3
247 112 my ($self, $args) = @_;
248  
249 # DWIM!
250 112 ▶ if (defined $args->{input}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"input"}) 4 108 112
251 4 ▶ if ($args->{input} eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{'input'} eq '-') { } 1 3 4
252 1 ▶ open my $fh, '<&', \*STDIN
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<&", \*STDIN or LOGCROAK("dup(): $Data::Embed::Writer::OS_ERROR") 1 0 1
253 or LOGCROAK "dup(): $OS_ERROR";
254 1 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode(\\*STDIN): $Data::Embed::Writer::OS_ERROR") 1 0 1
255 or LOGCROAK "binmode(\\*STDIN): $OS_ERROR";
256 1 $args->{fh} = $fh;
257 } ## end if ($args->{input} eq ...)
258 else {
259 3 my $ref = ref $args->{input};
260 3 ▶ if ((!$ref) || ($ref eq 'SCALAR')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ref or $ref eq 'SCALAR') { } 2 1 3
Condition100%3/3
not $ref or $ref eq "SCALAR"
l!l&&r!l&&!r
111
MC/DC100%2/2
not $ref or $ref eq "SCALAR"
not $ref $ref eq "SCALAR"
Truth table100%3/3
not(A) or B
A= not $refB= $ref eq "SCALAR"
ABresult
1X1
011
000
261 2 $args->{filename} = $args->{input};
262 }
263 else {
264 1 $args->{fh} = $args->{input};
265 }
266 } ## end else [ if ($args->{input} eq ...)]
267 } ## end if (defined $args->{input...})
268  
269 112 ▶ if (defined $args->{fh}) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $args->{'fh'}) { } 8 104 112
elsif (defined $args->{'filename'}) { } 4 100 104
elsif (defined $args->{'data'}) { } 100 0 100
270 8 return $self->add_fh(@{$args}{qw< name fh >});
271 }
272 elsif (defined $args->{filename}) {
273 4 return $self->add_file(@{$args}{qw< name filename >});
274 }
275 elsif (defined $args->{data}) {
276 100 return $self->add_data(@{$args}{qw< name data >});
277 }
278  
279 0 LOGCROAK "add() needs some input";
280 0 return; # unreached
281 } ## end sub _add
282  
283 111 ▶sub add_file {
Subroutine add_file: called CC=5 SCAR=16.5
Pod documented
284 111 my ($self, $name, $filename) = @_;
285 111 ▶ $name = '' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 111 111
286 111 ▶ my $print_name =
Branch: 1 branch
BranchTrueFalseTotal
ref $filename eq 'SCALAR' ? : 107 4 111
287 (ref($filename) eq 'SCALAR') ? 'internal data' : $filename;
288 111 DEBUG "add_file(): $name => $filename";
289  
290 # To make it work with references to scalars in perl pre-5.14
291 # we split open() and binmode()
292 111 ▶ open my $fh, '<', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or LOGCROAK("open('${print_name}'): $Data::Embed::Writer::OS_ERROR") 111 0 111
293 or LOGCROAK "open('$print_name'): $OS_ERROR";
294 111 ▶ binmode $fh
Branch: 1 branch
BranchTrueFalseTotal
binmode $fh or LOGCROAK("binmode('${print_name}') failed") 111 0 111
295 or LOGCROAK "binmode('$print_name') failed";
296  
297 111 return $self->add_fh($name, $fh);
298 } ## end sub add_file
299  
300 102 ▶sub add_data {
Subroutine add_data: called CC=1 SCAR=0.0
Pod documented
301 102 my ($self, $name) = @_;
302 102 return $self->add_file($name, \$_[2]);
303 }
304  
305 121 ▶sub add_fh {
Subroutine add_fh: called CC=7 SCAR=19.8
Pod documented
306 121 my ($self, $name, $input_fh) = @_;
307  
308 121 my $output_fh = $self->{output_fh};
309 121 my $data_length = 0; # go!
310 121 ▶ while (!eof $input_fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $input_fh) 121 121 242
311 121 my $buffer;
312 121 ▶ defined(my $nread = read $input_fh, $buffer, 4096)
Branch: 1 branch
BranchTrueFalseTotal
defined(my $nread = read($input_fh, $buffer, 4096)) or LOGCROAK("read(): $Data::Embed::Writer::OS_ERROR") 121 0 121
313 or LOGCROAK "read(): $OS_ERROR";
314 121 ▶ last unless $nread; # safe side?
Branch: 1 branch
BranchTrueFalseTotal
unless $nread 0 121 121
315 121 ▶ print {$output_fh} $buffer
Branch: 1 branch
BranchTrueFalseTotal
print {$output_fh;} $buffer or LOGCROAK("print(): $Data::Embed::Writer::OS_ERROR") 121 0 121
316 or LOGCROAK "print(): $OS_ERROR";
317 121 $data_length += $nread;
318 } ## end while (!eof $input_fh)
319  
320 # Add separator, not really needed but might come handy for
321 # peeking into the file
322 121 ▶ print {$output_fh} "\n\n"
Branch: 1 branch
BranchTrueFalseTotal
print {$output_fh;} "\n\n" or LOGCROAK("print(): $Data::Embed::Writer::OS_ERROR") 121 0 121
323 or LOGCROAK "print(): $OS_ERROR";
324  
325 121 ▶ $name = '' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 121 121
326 121 push @{$self->{index}}, sprintf "%d %s\n", $data_length, escape($name);
327  
328 121 return $self;
329 } ## end sub add_fh
330  
331 62 ▶sub write_index {
Subroutine write_index: called CC=3 SCAR=11.0
Pod documented
332 62 my $self = shift;
333 62 my ($output_fh, $index) = @{$self}{qw< output_fh index >};
334 62 ▶ print {$output_fh} STARTER, @$index, TERMINATOR
Branch: 1 branch
BranchTrueFalseTotal
print {$output_fh;} "Data::Embed/index/begin\n", @$index, "Data::Embed/index/end\n" or LOGCROAK("print(): $Data::Embed::Writer::OS_ERROR") 62 0 62
335 or LOGCROAK "print(): $OS_ERROR";
336 62 delete $self->{$_} for qw< output_fh index >;
337 62 return;
338 } ## end sub write_index
339  
340 62 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
341 62 my $self = shift;
342 62 ▶ $self->write_index() if exists $self->{output_fh};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"output_fh"} 3 59 62
343 62 return;
344 }
345  
346 9 1;
« Embed/File.pm ↑ Summary Embed.pm »