blib/lib/HTML/HTMLDoc.pm

filter: Statementstmt 64.7% 311 / 480 Branchbran 56.3% 71 / 126 Conditioncond 54.8% 45 / 82 MC/DCmcdc 25.0% 10 / 40 Subroutinesub 72.2% 52 / 72 Podpod 98.0% 51 / 52 totaltotal 63.3% 540 / 852 CC 99 SCAR 19.6
CC
99
Cov
62%
_prepare_input_file
30.0
_test_color
19.5
_cleanup
12.0
CRAP 7.1
↑ Summary blib/lib/HTML/HTMLDoc/PDF.pm »
1 package HTML::HTMLDoc;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use IPC::Open3 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTML::HTMLDoc::PDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 @ISA = qw();
12 1 $VERSION = '0.19';
13 1 my $DEBUG = 0;
14  
15 ###############
16 # create a new Object
17 # param:
18 # return: object:HTML::HTMLDOC
19 ###############
20 sub new {
21 4 ▶ my $package = shift;
Subroutine new: called CC=2 SCAR=7.5
Pod documented
22  
23 4 my $self = {};
24 4 bless($self, $package);
25  
26 4 ▶ while (my $key = shift) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = shift()) 0 4 4
27 0 my $value = shift;
28 0 $self->{'config'}->{$key} = $value;
29 }
30  
31 4 $self->_init();
32  
33 4 return $self;
34 }
35  
36 ###############
37 # initialises the Object with the basic parameters
38 # param: -
39 # return: -
40 ###############
41 sub _init {
42 4 ▶ my $self = shift;
Subroutine _init: called CC=8 SCAR=24.5
43  
44 4 ▶ if ((not defined $self->{'config'}->{'mode'}) || ($self->{'config'}->{'mode'} ne 'file' && $self->{'config'}->{'mode'} ne 'ipc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"config"}{"mode"} or $self->{"config"}{"mode"} ne "file" and $self->{"config"}{"mode"} ne "ipc") 4 0 4
Condition16%1/6
not defined $self->{"config"}{"mode"} or $self->{"config"}{"mode"} ne "file" and $self->{"config"}{"mode"} ne "ipc"
l!l&&r!l&&!r
400
$self->{"config"}{"mode"} ne "file" and $self->{"config"}{"mode"} ne "ipc"
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $self->{"config"}{"mode"} or $self->{"config"}{"mode"} ne "file" and $self->{"config"}{"mode"} ne "ipc"
not defined $self->{"config"}{"mode"} $self->{"config"}{"mode"} ne "file" $self->{"config"}{"mode"} ne "ipc"
Truth table25%1/4
not(A) or B and C
A= not defined $self->{"config"}{"mode"}B= $self->{"config"}{"mode"} ne "file"C= $self->{"config"}{"mode"} ne "ipc"
ABCresult
1XX1
0111
00X0
0100
45 4 $self->{'config'}->{'mode'} = 'ipc';
46 }
47  
48 4 ▶ if ( (!$self->{'config'}->{'tmpdir'}) || (!-d $self->{'config'}->{'tmpdir'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"config"}{"tmpdir"} and -d $self->{"config"}{"tmpdir"}) 4 0 4
Condition33%1/3
$self->{"config"}{"tmpdir"} and -d $self->{"config"}{"tmpdir"}
!ll&&!rl&&r
400
MC/DC0%0/2
$self->{"config"}{"tmpdir"} and -d $self->{"config"}{"tmpdir"}
$self->{"config"}{"tmpdir"} -d $self->{"config"}{"tmpdir"}
Truth table33%1/3
A and B
A= $self->{"config"}{"tmpdir"}B= -d $self->{"config"}{"tmpdir"}
ABresult
0X0
100
111
49 4 $self->{'config'}->{'tmpdir'} = '/tmp';
50 }
51  
52 4 ▶ if ( defined($self->{'config'}->{'bindir'}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'config'}{'bindir'}) { } 0 4 4
53 0 ▶ $self->{'config'}->{'bindir'} .= "/" if ( $self->{'config'}->{'bindir'} !~ /\/$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"}{"bindir"} =~ m[/$] 0 0 0
54 } else {
55 4 $self->{'config'}->{'bindir'} = '';
56 }
57  
58 4 $self->{'errors'} = [];
59 4 $self->{'doc_config'} = {};
60  
61 4 $self->set_page_size('universal');
62 4 $self->portrait();
63 4 $self->set_charset('iso-8859-1');
64 4 $self->_set_doc_config('quiet');
65 4 $self->set_output_format('pdf');
66  
67 # standard-header and footer
68 4 $self->set_footer('.', '1', '.');
69 4 $self->set_header('.', 't', '.');
70  
71 }
72  
73 ###############
74 # Store or get a global configuration value
75 # testet
76 # param: key:STRING, value:STRING
77 # return: 1
78 ###############
79 sub _config {
80 2 ▶ my $self = shift;
Subroutine _config: called CC=2 SCAR=7.1
81 2 my $key = shift;
82 2 my $value = shift;
83  
84 2 my $ret;
85 2 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 0 2 2
86 0 $self->{'config'}->{$key} = $value;
87 } else {
88 2 $ret = $self->{'config'}->{$key};
89 }
90 2 return $ret;
91 }
92  
93 ###############
94 # stores a specific value for formating the outputdoc
95 # testet
96 # param: key:STRING, value:STRING
97 # return: 1
98 ###############
99 sub _set_doc_config {
100 95 ▶ my $self = shift;
Subroutine _set_doc_config: called CC=6 SCAR=18.0
101 95 my $key = shift;
102 95 my $value = shift;
103  
104 95 ▶ if (ref($value) && (ref($value) eq 'ARRAY') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value and ref $value eq 'ARRAY') { } 16 79 95
Condition66%2/3
ref $value and ref $value eq "ARRAY"
!ll&&!rl&&r
79016
MC/DC50%1/2
ref $value and ref $value eq "ARRAY"
ref $value ref $value eq "ARRAY"
Truth table66%2/3
A and B
A= ref $valueB= ref $value eq "ARRAY"
ABresult
0X0
100
111
105 # the value is an array, store it in an array too
106 16 ▶ if ( !$self->{'doc_config'}->{$key} || ref($self->{'doc_config'}->{$key}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"doc_config"}{$key} or ref $self->{"doc_config"}{$key} ne "ARRAY") 8 8 16
Condition66%2/3
not $self->{"doc_config"}{$key} or ref $self->{"doc_config"}{$key} ne "ARRAY"
l!l&&r!l&&!r
808
MC/DC50%1/2
not $self->{"doc_config"}{$key} or ref $self->{"doc_config"}{$key} ne "ARRAY"
not $self->{"doc_config"}{$key} ref $self->{"doc_config"}{$key} ne "ARRAY"
Truth table66%2/3
not(A) or B
A= not $self->{"doc_config"}{$key}B= ref $self->{"doc_config"}{$key} ne "ARRAY"
ABresult
1X1
011
000
107 # create a new array
108 8 $self->{'doc_config'}->{$key} = [];
109 }
110 16 foreach my $single_value(@{$value}) {
111 18 push(@{$self->{'doc_config'}->{$key}}, $single_value);
112 }
113 } else {
114 79 $self->{'doc_config'}->{$key} = $value;
115 }
116  
117 95 return 1;
118 }
119  
120 ###############
121 # deletes a specific config
122 # testet
123 # param: key:STRING
124 # return: value:STRING
125 ###############
126 sub _delete_doc_config {
127 46 ▶ my $self = shift;
Subroutine _delete_doc_config: called CC=6 SCAR=17.9
128 46 my $key = shift;
129 46 my $value = shift;
130  
131 46 ▶ if (exists $self->{'doc_config'}->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"doc_config"}{$key}) 21 25 46
132 21 my $set_value = $self->_get_doc_config($key);
133 21 ▶ if ( (ref($set_value) eq 'ARRAY') && $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $set_value eq 'ARRAY' and $value) { } 8 13 21
Condition100%3/3
ref $set_value eq "ARRAY" and $value
!ll&&!rl&&r
678
MC/DC100%2/2
ref $set_value eq "ARRAY" and $value
ref $set_value eq "ARRAY" $value
Truth table100%3/3
A and B
A= ref $set_value eq "ARRAY"B= $value
ABresult
0X0
100
111
134 # remove specific value only
135 # find the position of the value
136 8 ▶ for(my $i=0; $i<@{$set_value}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$set_value;}) 14 6 20
137 14 ▶ if ( $set_value->[$i] eq $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($set_value->[$i] eq $value) 2 12 14
138 2 splice(@{$set_value}, $i, 1);
139 2 last;
140 }
141 }
142 } else {
143 # delete the singlevalue
144 13 delete $self->{'doc_config'}->{$key};
145 }
146 }
147 }
148  
149  
150 ###############
151 # tells a specific value for formating the outputdoc
152 # testet
153 # param: key:STRING
154 # return: value:STRING
155 ###############
156 sub _get_doc_config {
157 80 ▶ my $self = shift;
Subroutine _get_doc_config: called CC=1 SCAR=0.0
158 80 my $key = shift;
159 80 return $self->{'doc_config'}->{$key};
160 }
161  
162 ###############
163 # returns all the configuration keys
164 # param: key:STRING
165 # return: value:STRING
166 ###############
167 sub _get_doc_config_keys {
168 4 ▶ my $self = shift;
Subroutine _get_doc_config_keys: called CC=2 SCAR=7.0
169  
170 4 my @keys = keys %{$self->{'doc_config'}};
171 4 ▶ print STDERR "Keys: @keys\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 4 4
172 4 return @keys;
173 }
174  
175 ###############
176 # tests if the parameter exists in the array
177 # of allowed params
178 # testet
179 # param: key:STRING, \@allowed
180 # return: 1/0
181 ###############
182 sub _test_params {
183 59 ▶ my $self = shift;
Subroutine _test_params: called CC=3 SCAR=11.0
184 59 my $param = shift;
185 59 my $allowed = shift;
186  
187 59 my $ok = 0;
188 59 foreach my $aparam (@{$allowed}) {
189 293 ▶ if (lc($param) eq lc($aparam)) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $param eq lc $aparam) 55 238 293
190 55 $ok=1;
191 55 last;
192 }
193 }
194  
195 59 return $ok;
196 }
197  
198  
199 #######################################
200 # public Methods for configuring behaviour and style of the
201 # Document
202 #######################################
203  
204 ###############
205 # sets the size of the pages - default: a4
206 # testet
207 # param: letter, a4, WxH{in,cm,mm}
208 # return: 1/0
209 ###############
210 sub set_page_size {
211 7 ▶ my $self = shift;
Subroutine set_page_size: called CC=6 SCAR=24.1
Pod documented
212 7 my $value = shift;
213  
214 7 ▶ if ( !$value && $value ne 'a4' && $value ne 'letter' && $value ne 'universal' && $value!~/^\d+x\d+(?:in|cm|mm)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $value and $value ne "a4" and $value ne "letter" and $value ne "universal" and not $value =~ /^\d+x\d+(?:in|cm|mm)/) 0 7 7
Condition33%4/12
not $value and $value ne "a4" and $value ne "letter" and $value ne "universal" and not $value =~ /^\d+x\d+(?:in|cm|mm)/
!ll&&!rl&&r
700
not $value and $value ne "a4" and $value ne "letter" and $value ne "universal"
!ll&&!rl&&r
700
not $value and $value ne "a4" and $value ne "letter"
!ll&&!rl&&r
700
not $value and $value ne "a4"
!ll&&!rl&&r
700
MC/DC0%0/5
not $value and $value ne "a4" and $value ne "letter" and $value ne "universal" and not $value =~ /^\d+x\d+(?:in|cm|mm)/
not $value $value ne "a4" $value ne "letter" $value ne "universal" not $value =~ /^\d+x\d+(?:in|cm|mm)/
Truth table16%1/6
not(A) and B and C and D and not(E)
A= not $valueB= $value ne "a4"C= $value ne "letter"D= $value ne "universal"E= not $value =~ /^\d+x\d+(?:in|cm|mm)/
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
215 0 $self->error("unknown value for pagesize: $value");
216 0 return 0;
217 }
218  
219 7 $self->_set_doc_config('size', $value);
220 7 return 1;
221 }
222  
223 ###############
224 # reads out the page-size
225 # param: letter, a4, WxH{in,cm,mm}
226 # return: 1/0
227 ###############
228 sub get_page_size {
229 3 ▶ my $self = shift;
Subroutine get_page_size: called CC=1 SCAR=0.0
Pod undocumented
230 3 return $self->_get_doc_config('size');
231 }
232  
233 ###############
234 # sets the master-password of the doc
235 # testet
236 # param: password:STRING
237 # return: 1/0
238 ###############
239 sub set_owner_password {
240 1 ▶ my $self = shift;
Subroutine set_owner_password: called CC=1 SCAR=0.0
Pod documented
241 1 my $value = shift;
242 1 $self->_set_doc_config('owner-password', $value);
243 1 return 1;
244 }
245  
246 ###############
247 # sets the user-password of the doc
248 # testet
249 # param: password:STRING
250 # return: 1/0
251 ###############
252 sub set_user_password {
253 1 ▶ my $self = shift;
Subroutine set_user_password: called CC=1 SCAR=0.0
Pod documented
254 1 my $value = shift;
255 1 $self->_set_doc_config('user-password', $value);
256 1 return 1;
257 }
258  
259 # all,annotate,copy,modify,print,no-annotate,no-copy,no-modify,no-print,none
260 ###############
261 # sets the master-password of the doc
262 # testet
263 # param: password:STRING
264 # return: 1/0
265 ###############
266 sub set_permissions {
267 15 ▶ my $self = shift;
Subroutine set_permissions: called CC=8 SCAR=21.2
Pod documented
268 15 my @values = @_;
269  
270 15 my $thiskey = 'permissions';
271  
272 15 my @allowed = ('all','annotate','copy','modify','print','no-annotate','no-copy','no-modify','no-print','none');
273 # test the set value
274 15 ▶ if ($#values==-1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#values == -1) 0 15 15
275 0 $self->error("wrong permission set: no values");
276 0 return 0;
277 }
278 15 ▶ for( my $i=0; $i<=$#values; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#values) 15 15 30
279 15 $values[$i] = lc($values[$i]);
280 15 ▶ if ( !$self->_test_params($values[$i], \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($values[$i], \@allowed)) 0 15 15
281 # wrong permission set
282 0 $self->error("wrong permission set: $values[$i]");
283 0 return 0;
284 }
285 }
286  
287 15 foreach my $value(@values) {
288 # take care of the combination of the options
289 15 ▶ if ( $value eq 'all' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($value eq 'all') { } 1 14 15
elsif ($value eq 'none') { } 2 12 14
290 # delete all
291 1 $self->_delete_doc_config($thiskey);
292 } elsif( $value eq 'none' ) {
293 # delete all
294 2 $self->_delete_doc_config($thiskey);
295 } else {
296 # delete the corresponding flag
297 12 ▶ if ( $value =~/^no-(.+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^no-(.+)/) { } 6 6 12
298 6 my $key = $1;
299 6 $self->_delete_doc_config($thiskey, $key);
300 } else {
301 6 $self->_delete_doc_config($thiskey, "no-$value");
302 }
303 }
304  
305 15 $self->_set_doc_config('permissions', [$value]);
306 }
307 # enable encryption since without it there is no effect.
308 15 $self->enable_encryption();
309 15 return 1;
310 }
311  
312 ###############
313 # sets to duplex for two-sided printing
314 # testet
315 # param: -
316 # return: 1/0
317 ###############
318 sub duplex_on {
319 0 ▶ my $self = shift;
Subroutine duplex_on: not called CC=1 SCAR=6.9
Pod documented
320  
321 0 $self->_set_doc_config('duplex', '');
322 0 $self->_delete_doc_config('no-duplex');
323 0 return 1;
324 }
325  
326 ###############
327 # disable duplex / two-sided printing
328 # testet
329 # param: -
330 # return: 1/0
331 ###############
332 sub duplex_off {
333 0 ▶ my $self = shift;
Subroutine duplex_off: not called CC=1 SCAR=6.9
Pod documented
334  
335 0 $self->_set_doc_config('no-duplex', '');
336 0 $self->_delete_doc_config('duplex');
337 0 return 1;
338 }
339  
340 ###############
341 # sets the pages to portrait
342 # testet
343 # param: -
344 # return: 1/0
345 ###############
346 sub landscape {
347 1 ▶ my $self = shift;
Subroutine landscape: called CC=1 SCAR=0.0
Pod documented
348  
349 1 $self->_set_doc_config('landscape', '');
350 1 $self->_delete_doc_config('portrait');
351 1 return 1;
352 }
353  
354 ###############
355 # sets the pages to portrait
356 # testet
357 # param: -
358 # return: 1/0
359 ###############
360 sub portrait {
361 5 ▶ my $self = shift;
Subroutine portrait: called CC=1 SCAR=0.0
Pod documented
362  
363 5 $self->_set_doc_config('portrait', '');
364 5 $self->_delete_doc_config('landscape');
365 5 return 1;
366 }
367  
368 ###############
369 # turns the title on
370 # param: -
371 # return: 1/0
372 ###############
373 sub title {
374 0 ▶ my $self = shift;
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
375  
376 0 $self->_set_doc_config('title', '');
377 0 $self->_delete_doc_config('no-title');
378 0 return 1;
379 }
380  
381 ###############
382 # turns the title off
383 # param: -
384 # return: 1/0
385 ###############
386 sub no_title {
387 0 ▶ my $self = shift;
Subroutine no_title: not called CC=1 SCAR=6.9
Pod documented
388  
389 0 $self->_set_doc_config('no-title', '');
390 0 $self->_delete_doc_config('title');
391 0 return 1;
392 }
393  
394 ###############
395 # sets the footer
396 # testet
397 # param: left:CHAR, center:CHAR, right:CHAR
398 # return: 1/0
399 ###############
400 sub set_footer {
401 6 ▶ my $self = shift;
Subroutine set_footer: called CC=4 SCAR=14.6
Pod documented
402 6 my $left = shift;
403 6 my $center = shift;
404 6 my $right = shift;
405  
406 6 my @allowed = ('.', ':', '/', '1', 'a', 'A', 'c', 'C', 'd', 'D', 'h', 'i', 'I', 'l', 't', 'T','u');
407 6 ▶ if (!$self->_test_params($left, \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($left, \@allowed)) 1 5 6
408 1 $self->error("wrong left-footer-option: $left");
409 1 return 0;
410 }
411 5 ▶ if (!$self->_test_params($center, \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($center, \@allowed)) 0 5 5
412 0 $self->error("wrong center-footer-option: $left");
413 0 return 0;
414 }
415 5 ▶ if (!$self->_test_params($right, \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($right, \@allowed)) 0 5 5
416 0 $self->error("wrong right-footer-option: $left");
417 0 return 0;
418 }
419  
420 5 $self->_set_doc_config('footer', "${left}${center}${right}");
421  
422 5 return 1;
423 }
424  
425 ###############
426 # sets the header
427 # testet
428 # param: left:CHAR, center:CHAR, right:CHAR
429 # return: 1/0
430 ###############
431 sub set_header {
432 7 ▶ my $self = shift;
Subroutine set_header: called CC=4 SCAR=14.6
Pod documented
433 7 my $left = shift;
434 7 my $center = shift;
435 7 my $right = shift;
436  
437 7 my @allowed = ('.', ':', '/', '1', 'a', 'A', 'c', 'C', 'd', 'D', 'h', 'i', 'I', 'l','L', 't', 'T','u');
438 7 ▶ if (!$self->_test_params($left, \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($left, \@allowed)) 1 6 7
439 1 $self->error("wrong left-header-option: $left");
440 1 return 0;
441 }
442 6 ▶ if (!$self->_test_params($center, \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($center, \@allowed)) 0 6 6
443 0 $self->error("wrong center-header-option: $left");
444 0 return 0;
445 }
446 6 ▶ if (!$self->_test_params($right, \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($right, \@allowed)) 0 6 6
447 0 $self->error("wrong right-header-option: $left");
448 0 return 0;
449 }
450  
451 6 $self->_set_doc_config('header', "${left}${center}${right}");
452  
453 6 return 1;
454 }
455  
456 ###############
457 # turns the links on
458 # param: -
459 # return: 1/0
460 ###############
461 sub links {
462 1 ▶ my $self = shift;
Subroutine links: called CC=1 SCAR=0.0
Pod documented
463  
464 1 $self->_set_doc_config('links', '');
465 1 $self->_delete_doc_config('no-links');
466 1 return 1;
467 }
468  
469 ###############
470 # turns the links off
471 # param: -
472 # return: 1/0
473 ###############
474 sub no_links {
475 1 ▶ my $self = shift;
Subroutine no_links: called CC=1 SCAR=0.0
Pod documented
476  
477 1 $self->_set_doc_config('no-links', '');
478 1 $self->_delete_doc_config('links');
479 1 return 1;
480 }
481  
482 ###############
483 # sets the search path for files in a document
484 # param: -
485 # return: 1/0
486 ###############
487 sub path {
488 1 ▶ my $self = shift;
Subroutine path: called CC=1 SCAR=0.0
Pod documented
489 1 my $sp = shift;
490  
491 1 $self->_set_doc_config('path', $sp);
492 1 return 1;
493 }
494  
495 ###############
496 # sets the right margin
497 # testet
498 # param: margin|NUM, measure:in,cm,mm
499 # return: 1/0
500 ###############
501 sub set_right_margin {
502 5 ▶ my $self = shift;
Subroutine set_right_margin: called CC=2 SCAR=6.9
Pod documented
503 5 my $margin = shift;
504 5 ▶ my $m = shift || 'cm';
Condition100%2/2
shift() || 'cm'
l!l
32
MC/DC100%1/1
shift() || 'cm'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
505 5 return $self->_set_margin('right', $margin, $m);
506 }
507  
508 ###############
509 # sets the left margin
510 # testet
511 # param: margin|NUM, measure:in,cm,mm
512 # return: 1/0
513 ###############
514 sub set_left_margin {
515 1 ▶ my $self = shift;
Subroutine set_left_margin: called CC=2 SCAR=7.0
Pod documented
516 1 my $margin = shift;
517 1 ▶ my $m = shift || 'cm';
Condition50%1/2
shift() || 'cm'
l!l
01
MC/DC0%0/1
shift() || 'cm'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
518 1 return $self->_set_margin('left', $margin, $m);
519 }
520  
521 ###############
522 # sets the bottom margin
523 # param: margin|NUM, measure:in,cm,mm
524 # return: 1/0
525 ###############
526 sub set_bottom_margin {
527 1 ▶ my $self = shift;
Subroutine set_bottom_margin: called CC=2 SCAR=7.0
Pod documented
528 1 my $margin = shift;
529 1 ▶ my $m = shift || 'cm';
Condition50%1/2
shift() || 'cm'
l!l
01
MC/DC0%0/1
shift() || 'cm'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
530 1 return $self->_set_margin('bottom', $margin, $m);
531 }
532  
533 ###############
534 # sets the top margin
535 # param: margin|NUM, measure:in,cm,mm
536 # return: 1/0
537 ###############
538 sub set_top_margin {
539 1 ▶ my $self = shift;
Subroutine set_top_margin: called CC=2 SCAR=7.0
Pod documented
540 1 my $margin = shift;
541 1 ▶ my $m = shift || 'cm';
Condition50%1/2
shift() || 'cm'
l!l
01
MC/DC0%0/1
shift() || 'cm'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
542 1 return $self->_set_margin('top', $margin, $m);
543 }
544  
545  
546 sub _set_margin {
547 8 ▶ my $self = shift;
Subroutine _set_margin: called CC=5 SCAR=16.1
548 8 my $where = shift;
549 8 my $margin = shift;
550 8 my $m = shift;
551  
552 # test the values
553 8 ▶ if ( $margin!~/^\d*\.?\d+$/ || ( ($m ne 'in') && ($m ne 'cm') && ($m ne 'mm') )) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $margin =~ /^\d*\.?\d+$/ or $m ne "in" and $m ne "cm" and $m ne "mm") 1 7 8
Condition88%8/9
not $margin =~ /^\d*\.?\d+$/ or $m ne "in" and $m ne "cm" and $m ne "mm"
l!l&&r!l&&!r
026
$m ne "in" and $m ne "cm" and $m ne "mm"
!ll&&!rl&&r
611
$m ne "in" and $m ne "cm"
!ll&&!rl&&r
152
MC/DC25%1/4
not $margin =~ /^\d*\.?\d+$/ or $m ne "in" and $m ne "cm" and $m ne "mm"
not $margin =~ /^\d*\.?\d+$/ $m ne "in" $m ne "cm" $m ne "mm"
Truth table40%2/5
not(A) or B and C and D
A= not $margin =~ /^\d*\.?\d+$/B= $m ne "in"C= $m ne "cm"D= $m ne "mm"
ABCDresult
1XXX1
01111
00XX0
010X0
01100
554 1 $self->error("wrong arguments for $where-margin: $margin $m");
555 1 return 0;
556 }
557  
558 7 $self->_set_doc_config($where, "$margin$m");
559 7 return 1;
560 }
561  
562 ###############
563 # sets the color of the body
564 # testet
565 # param: color:hex
566 # return: 1/0
567 ###############
568 sub set_bodycolor {
569 4 ▶ my $self = shift;
Subroutine set_bodycolor: called CC=2 SCAR=6.9
Pod documented
570  
571 4 my $ret;
572 4 my $color = $self->_test_color(@_);
573 4 ▶ if (!$color) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $color) { } 1 3 4
574 1 $self->error("wrong value set for bodycolor");
575 1 $ret = 0;
576 } else {
577 3 $ret = $self->_set_doc_config('bodycolor', $color);
578 }
579  
580 4 return $ret;
581 }
582  
583 ###############
584 # internal method for testing and converting colors
585 # testet
586 # param: color:hex || color: rgb || color: name
587 # return: color:hex
588 ###############
589 sub _test_color {
590 11 ▶ my $self = shift;
Subroutine _test_color: called CC=16 SCAR=29.7
591 11 my @colors = @_;
592 11 my $ret;
593  
594 11 ▶ if( (@colors == 1) && $colors[0]=~/^#[0-9a-f]{6}$/i ) {
Branch: 3 branches
BranchTrueFalseTotal
if (@colors == 1 and $colors[0] =~ /^#[0-9a-f]{6}$/i) { } 2 9 11
elsif (@colors == 3) { } 4 5 9
elsif (@colors == 1) { } 5 0 5
Condition100%3/3
@colors == 1 and $colors[0] =~ /^#[0-9a-f]{6}$/i
!ll&&!rl&&r
452
MC/DC100%2/2
@colors == 1 and $colors[0] =~ /^#[0-9a-f]{6}$/i
@colors == 1 $colors[0] =~ /^#[0-9a-f]{6}$/i
Truth table100%3/3
A and B
A= @colors == 1B= $colors[0] =~ /^#[0-9a-f]{6}$/i
ABresult
0X0
100
111
595 # got hex-color
596 2 return $colors[0];
597 } elsif( @colors==3 ) {
598 # 3 input values, test if regular rgb is given
599 4 my ($r, $g, $b) = @colors;
600 4 ▶ if ($r=~/^\d{1,3}$/ && $g=~/^\d{1,3}$/ && $b=~/^\d{1,3}$/
Branch: 1 branch
BranchTrueFalseTotal
if ($r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/ and $r >= 0 and $r <= 255 and $b >= 0 and $b <= 255 and $g >= 0 and $g <= 255) 3 1 4
Condition54%13/24
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/ and $r >= 0 and $r <= 255 and $b >= 0 and $b <= 255 and $g >= 0 and $g <= 255
!ll&&!rl&&r
103
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/ and $r >= 0 and $r <= 255 and $b >= 0 and $b <= 255 and $g >= 0
!ll&&!rl&&r
103
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/ and $r >= 0 and $r <= 255 and $b >= 0 and $b <= 255
!ll&&!rl&&r
103
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/ and $r >= 0 and $r <= 255 and $b >= 0
!ll&&!rl&&r
103
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/ and $r >= 0 and $r <= 255
!ll&&!rl&&r
013
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/ and $r >= 0
!ll&&!rl&&r
004
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/
!ll&&!rl&&r
004
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/
!ll&&!rl&&r
004
MC/DC11%1/9
$r =~ /^\d{1,3}$/ and $g =~ /^\d{1,3}$/ and $b =~ /^\d{1,3}$/ and $r >= 0 and $r <= 255 and $b >= 0 and $b <= 255 and $g >= 0 and $g <= 255
$r =~ /^\d{1,3}$/ $g =~ /^\d{1,3}$/ $b =~ /^\d{1,3}$/ $r >= 0 $r <= 255 $b >= 0 $b <= 255 $g >= 0 $g <= 255
Truth table20%2/10
A and B and C and D and E and F and G and H and I
A= $r =~ /^\d{1,3}$/B= $g =~ /^\d{1,3}$/C= $b =~ /^\d{1,3}$/D= $r >= 0E= $r <= 255F= $b >= 0G= $b <= 255H= $g >= 0I= $g <= 255
ABCDEFGHIresult
0XXXXXXXX0
10XXXXXXX0
110XXXXXX0
1110XXXXX0
11110XXXX0
111110XXX0
1111110XX0
11111110X0
1111111100
1111111111
601 && $r>=0 && $r <=255 && $b>=0 && $b<=255 && $g>=0 && $g<=255) {
602 3 $ret = sprintf("#%02x%02x%02x", $r, $g, $b);
603 }
604 } elsif( @colors==1 ) {
605 5 foreach my $c( qw(red green blue cyan magenta yellow darkRed
606 darkGreen darkBlue darkCyan darkMagenta darkYellow white
607 lightGray gray darkGray black) ) {
608 53 ▶ if ($c eq $colors[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq $colors[0]) 2 51 53
609 2 $ret = $c;
610 2 last;
611 }
612 }
613 }
614  
615 9 return $ret;
616 }
617  
618 ###############
619 # sets the default font for the body
620 # testet
621 # param: fontface:STRING
622 # return: 1/0
623 ###############
624 sub set_bodyfont {
625 0 ▶ my $self = shift;
Subroutine set_bodyfont: not called CC=2 SCAR=17.9
Pod documented
626 0 my $font = shift;
627  
628 0 my $ret = 0;
629 0 my @allowed = qw(Arial Courier Helvetica Monospace Sans Serif Times);
630 0 ▶ if ( !$self->_test_params($font, \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_test_params($font, \@allowed)) { } 0 0 0
631 0 $self->error("illegal font set $font");
632 } else {
633 0 $self->_set_doc_config('bodyfont', $font);
634 0 $ret = 1;
635 }
636  
637 0 return $ret;
638 }
639  
640 ###############
641 # sets the default font for the document
642 # testet
643 # param: fontface:STRING
644 # return: 1/0
645 ###############
646 sub set_textfont {
647 0 ▶ my $self = shift;
Subroutine set_textfont: not called CC=2 SCAR=17.9
Pod documented
648 0 my $font = shift;
649  
650 0 my $ret = 0;
651 0 my @allowed = qw(Arial Courier Helvetica Monospace Sans Serif Times);
652 0 ▶ if ( !$self->_test_params($font, \@allowed) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_test_params($font, \@allowed)) { } 0 0 0
653 0 $self->error("illegal font set $font");
654 } else {
655 0 $self->_set_doc_config('textfont', $font);
656 0 $ret = 1;
657 }
658  
659 0 return $ret;
660 }
661  
662 ###############
663 # sets the font size for body text
664 # param: size:NUM
665 # return: 1/0
666 ###############
667 sub set_fontsize {
668 3 ▶ my $self = shift;
Subroutine set_fontsize: called CC=2 SCAR=6.9
Pod documented
669 3 my $fsize = shift;
670 3 ▶ if ($fsize =~ /^\d+(\.\d+){0,1}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fsize =~ /^\d+(\.\d+){0,1}$/) { } 2 1 3
671 2 return $self->_set_doc_config('fontsize', $fsize);
672 } else {
673 1 $self->error("illegal font size $fsize");
674 1 return 0;
675 }
676 }
677  
678  
679 ###############
680 # takes an image-filename that is used as background
681 # for all Pages
682 # param: image:STRING
683 # return: 1/0
684 ###############
685 sub set_bodyimage {
686 0 ▶ my $self = shift;
Subroutine set_bodyimage: not called CC=2 SCAR=17.9
Pod documented
687 0 my $image = shift;
688  
689 0 ▶ if ( ! -f "$image" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "$image") 0 0 0
690 0 $self->error("Backgroundimage $image could not be found");
691 0 return 0;
692 }
693  
694 0 $self->_set_doc_config('bodyimage', $image);
695 0 return 1;
696 }
697  
698 ###############
699 # takes an image-filename that is used as logoimage
700 # param: image:STRING
701 # return: 1/0
702 ###############
703 sub set_logoimage {
704 2 ▶ my $self = shift;
Subroutine set_logoimage: called CC=2 SCAR=6.9
Pod documented
705 2 my $image = shift;
706  
707 2 ▶ if ( ! -f "$image" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "$image") 1 1 2
708 1 $self->error("Logoimage $image could not be found");
709 1 return 0;
710 }
711  
712 1 $self->_set_doc_config('logoimage', $image);
713 1 return 1;
714 }
715  
716 ###############
717 # returns a previous set logo-image
718 # param: -
719 # return: image:STRING
720 ###############
721 sub get_logoimage {
722 1 ▶ my $self = shift;
Subroutine get_logoimage: called CC=1 SCAR=0.0
Pod documented
723 1 return $self->_get_doc_config('logoimage');
724 }
725  
726 ###############
727 # takes an image-filename that is used as letterhead
728 # param: image:STRING
729 # return: 1/0
730 ###############
731 sub set_letterhead {
732 1 ▶ my $self = shift;
Subroutine set_letterhead: called CC=2 SCAR=7.5
Pod documented
733 1 my $image = shift;
734  
735 1 ▶ if ( ! -f "$image" ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "$image") 0 1 1
736 0 $self->error("Letterhead $image could not be found");
737 0 return 0;
738 }
739  
740 1 $self->_set_doc_config('letterhead', $image);
741  
742 # tell htmldoc to use this letterhead
743 1 $self->set_header('.', 'L', '.');
744  
745 1 return 1;
746 }
747  
748 ###############
749 # returns a previous set letterhead image
750 # param: -
751 # return: image:STRING
752 ###############
753 sub get_letterhead {
754 1 ▶ my $self = shift;
Subroutine get_letterhead: called CC=1 SCAR=0.0
Pod documented
755 1 return $self->_get_doc_config('letterhead');
756 }
757  
758  
759 ###############
760 # set the witdh in px for the background image
761 # param: width:INT
762 # return: 1/0
763 ###############
764 sub set_browserwidth {
765 2 ▶ my $self = shift;
Subroutine set_browserwidth: called CC=2 SCAR=6.9
Pod documented
766 2 my $width = shift;
767  
768 2 ▶ if ($width !~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($width =~ /^\d+$/) 1 1 2
769 1 $self->error("wrong browserwidth $width set");
770 1 return 0;
771 }
772  
773 1 $self->_set_doc_config('browserwidth', $width);
774 1 return 1;
775 }
776  
777 ###############
778 # sets the compression level
779 # param:
780 # return: 1/0
781 ###############
782 sub set_compression {
783 0 ▶ my $self = shift;
Subroutine set_compression: not called CC=1 SCAR=6.9
Pod documented
784 0 my $comp = shift;
785 0 return $self->_set_doc_config('compression', $comp);
786 }
787  
788 ###############
789 # sets the JPEG-Kompression
790 # param: 0-100 (default 50)
791 # return: 1/0
792 ###############
793 sub set_jpeg_compression {
794 5 ▶ my $self = shift;
Subroutine set_jpeg_compression: called CC=2 SCAR=6.9
Pod documented
795 5 my $comp = shift;
796 5 ▶ $comp = 75 if (not defined $comp);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $comp 1 4 5
797 5 return $self->_set_doc_config('jpeg', $comp);
798 }
799  
800 ###############
801 # sets the JPEG-Kompression value to the highest quality
802 # param: -
803 # return: 1/0
804 ###############
805 sub best_image_quality {
806 1 ▶ my $self = shift;
Subroutine best_image_quality: called CC=1 SCAR=0.0
Pod documented
807 1 return $self->set_jpeg_compression(100);
808 }
809  
810 ###############
811 # sets the JPEG-Kompression value to the highest quality
812 # param: -
813 # return: 1/0
814 ###############
815 sub low_image_quality {
816 1 ▶ my $self = shift;
Subroutine low_image_quality: called CC=1 SCAR=0.0
Pod documented
817 1 return $self->set_jpeg_compression(25);
818 }
819  
820 ###############
821 # sets the pagemode
822 # param: mode:[document,outline,fullscreen]
823 # return: 1/0
824 ###############
825 sub set_pagemode {
826 0 ▶ my $self = shift;
Subroutine set_pagemode: not called CC=2 SCAR=17.9
Pod documented
827 0 my $value = shift;
828  
829 #--pagemode {document,outline,fullscreen}
830 0 ▶ if (!$self->_test_params($value, ['document', 'outline', 'fullscreen']) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($value, ["document", "outline", "fullscreen"])) 0 0 0
831 #if ($value ne 'document' && $value ne 'outline' && $value ne 'fullscreen') {
832 0 $self->error("wrong pagemode: $value");
833 0 return 0;
834 }
835  
836 0 $self->_set_doc_config('pagemode', $value);
837 }
838  
839 ###############
840 # sets the page layout when opened in the viewer
841 # param: mode:[single,one,twoleft,tworight]
842 # return: 1/0
843 ###############
844 sub set_pagelayout {
845 0 ▶ my $self = shift;
Subroutine set_pagelayout: not called CC=2 SCAR=17.9
Pod documented
846 0 my $value = shift;
847  
848 #--pagemode {document,outline,fullscreen}
849 0 ▶ if (!$self->_test_params($value, ['single', 'one', 'twoleft', 'tworight']) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($value, ["single", "one", "twoleft", "tworight"])) 0 0 0
850 #if ($value ne 'document' && $value ne 'outline' && $value ne 'fullscreen') {
851 0 $self->error("wrong pagelayout: $value");
852 0 return 0;
853 }
854  
855 0 $self->_set_doc_config('pagelayout', $value);
856 }
857  
858  
859  
860 ###############
861 # sets the charset
862 # param: charset
863 # return: 1/0
864 ###############
865 sub set_charset {
866 4 ▶ my $self = shift;
Subroutine set_charset: called CC=1 SCAR=0.0
Pod documented
867 4 my $charset = shift;
868  
869 4 $self->_set_doc_config('charset', $charset);
870 4 return 1;
871 }
872  
873 ###############
874 # embedding the used fonts into the pdf-file
875 # testet
876 # param:
877 # return: 1/0
878 ###############
879 sub embed_fonts {
880 0 ▶ my $self = shift;
Subroutine embed_fonts: not called CC=1 SCAR=6.9
Pod documented
881 0 $self->_delete_doc_config('no-embedfonts');
882 0 $self->_set_doc_config('embedfonts', '');
883 0 return 1;
884 }
885  
886 ###############
887 # no font embedding
888 # testet
889 # param:
890 # return: 1/0
891 ###############
892 sub no_embed_fonts {
893 0 ▶ my $self = shift;
Subroutine no_embed_fonts: not called CC=1 SCAR=6.9
Pod documented
894 0 $self->_delete_doc_config('embedfonts');
895 0 $self->_set_doc_config('no-embedfonts', '');
896 0 return 1;
897 }
898  
899 ###############
900 # turns colors on in doc
901 # param: charset
902 # return: 1/0
903 ###############
904 sub color_on {
905 0 ▶ my $self = shift;
Subroutine color_on: not called CC=1 SCAR=6.9
Pod documented
906  
907 0 $self->_set_doc_config('color', '');
908 0 $self->_delete_doc_config('grey', '');
909 0 return 1;
910 }
911  
912 ###############
913 # turns colors off in doc
914 # param:
915 # return: 1/0
916 ###############
917 sub color_off {
918 0 ▶ my $self = shift;
Subroutine color_off: not called CC=1 SCAR=6.9
Pod documented
919  
920 0 $self->_set_doc_config('grey', '');
921 0 $self->_delete_doc_config('color', '');
922 0 return 1;
923 }
924  
925 ###############
926 # turns encryption off
927 # param: -
928 # return: 1/0
929 ###############
930 sub enable_encryption {
931 15 ▶ my $self = shift;
Subroutine enable_encryption: called CC=1 SCAR=0.0
Pod documented
932  
933 15 $self->_set_doc_config('encryption', '');
934 15 $self->_delete_doc_config('no-enryption', '');
935 15 return 1;
936 }
937  
938 ###############
939 # turns encryption off
940 # param: -
941 # return: 1/0
942 ###############
943 sub disable_encryption {
944 0 ▶ my $self = shift;
Subroutine disable_encryption: not called CC=1 SCAR=6.9
Pod documented
945  
946 0 $self->_set_doc_config('no-encryption', '');
947 0 $self->_delete_doc_config('enryption', '');
948 0 return 1;
949 }
950  
951 ###############
952 # sets the outputformat of the document
953 # param: format:STRING
954 # return: 1/0
955 ###############
956 sub set_output_format {
957 7 ▶ my $self = shift;
Subroutine set_output_format: called CC=2 SCAR=6.9
Pod documented
958 7 my $f = shift;
959  
960 7 my @allowed = qw(epub html pdf pdf11 pdf12 pdf13 pdf14 ps ps1 ps2 ps3);
961 7 ▶ if( !$self->_test_params($f, \@allowed)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_test_params($f, \@allowed)) 1 6 7
962 1 $self->error("Wrong output format set $f");
963 1 return 0;
964 }
965  
966 6 $self->_set_doc_config('format', $f);
967 6 return 1;
968 }
969  
970  
971 ####################################################
972 #
973 # Methods for outputting the result
974 #
975 ####################################################
976  
977  
978  
979 ###############
980 # sets the html-page that should be rendered
981 # param: html:STRING
982 # return: 1/0
983 ###############
984 sub set_html_content {
985 3 ▶ my $self = shift;
Subroutine set_html_content: called CC=1 SCAR=0.0
Pod documented
986 3 my $html = shift;
987  
988 3 $self->{'html'} = $html;
989 3 return 1;
990 }
991  
992 ###############
993 # returns the html-content
994 # param: -
995 # return: html:STRING
996 ###############
997 sub get_html_content {
998 3 ▶ my $self = shift;
Subroutine get_html_content: called CC=2 SCAR=6.9
Pod documented
999  
1000 3 ▶ if (ref($self->{'html'}) eq 'SCALAR') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"html"} eq "SCALAR") 1 2 3
1001 1 return ${$self->{'html'}};
1002 }
1003  
1004 2 return $self->{'html'};
1005 }
1006  
1007 ###############
1008 # sets the filename of the html-page that should be rendered
1009 # param: input_file:STRING
1010 # return: 1/0
1011 ###############
1012 sub set_input_file {
1013 0 ▶ my $self = shift;
Subroutine set_input_file: not called CC=2 SCAR=17.9
Pod documented
1014 0 my $infile = shift;
1015  
1016 0 ▶ if (-f $infile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $infile) 0 0 0
1017 0 $self->{'input_file'} = $infile;
1018 0 $self->{'config'}->{'mode'} = 'file';
1019 0 return 1;
1020 }
1021 0 return 0;
1022 }
1023  
1024 ###############
1025 # returns the input htmlfile
1026 # param: -
1027 # return: input_file:STRING
1028 ###############
1029 sub get_input_file {
1030 0 ▶ my $self = shift;
Subroutine get_input_file: not called CC=1 SCAR=6.9
Pod documented
1031 0 return $self->{'input_file'};
1032 }
1033  
1034  
1035 ###############
1036 # private: opens a temporary file and sets the
1037 # html-content in
1038 # param: -
1039 # return: filename:STRING
1040 ###############
1041 sub _prepare_input_file {
1042 0 ▶ my $self = shift;
Subroutine _prepare_input_file: not called CC=5 SCAR=34.0
1043  
1044 0 my $i=0;
1045 0 my $filename;
1046 0 ▶ return $filename if (defined ($filename = $self->{'input_file'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined($filename = $self->{"input_file"}) 0 0 0
1047  
1048 0 ▶ while($i<1000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 1000) 0 0 0
1049 0 my $randpart = int(rand(1000));
1050 0 $filename = $self->{'config'}->{'tmpdir'} . "/htmldoc$randpart.html";
1051  
1052 0 ▶ if (-f $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename) { } 0 0 0
1053 0 $i++;
1054 0 next;
1055 } else {
1056 0 last;
1057 }
1058 }
1059  
1060 0 my $file = new IO::File($filename, 'w');
1061 0 ▶ if (!$file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 0 0 0
1062 0 warn "could not open tempfile $!";
1063 0 return undef;
1064 }
1065 0 $file->print($self->get_html_content());
1066 0 $file->close();
1067 0 $self->{'config'}->{'tmpfile'} = $filename;
1068  
1069 0 return $filename;
1070 }
1071  
1072 ###############
1073 # private: cleans up, deletes the tempfile
1074 # param: -
1075 # return: -
1076 ###############
1077 sub _cleanup {
1078 0 ▶ my $self = shift;
Subroutine _cleanup: not called CC=3 SCAR=24.8
1079 unlink($self->{'config'}->{'tmpfile'})
1080 0 ▶ if ( (defined $self->{'config'}->{'tmpfile'}) && (-f $self->{'config'}->{'tmpfile'}) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"config"}{"tmpfile"} and -f $self->{"config"}{"tmpfile"} 0 0 0
Condition0%0/3
defined $self->{"config"}{"tmpfile"} and -f $self->{"config"}{"tmpfile"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"config"}{"tmpfile"} and -f $self->{"config"}{"tmpfile"}
defined $self->{"config"}{"tmpfile"} -f $self->{"config"}{"tmpfile"}
Truth table0%0/3
A and B
A= defined $self->{"config"}{"tmpfile"}B= -f $self->{"config"}{"tmpfile"}
ABresult
0X0
100
111
1081 }
1082  
1083 ###############
1084 # finaly produces the pdf-output
1085 # param: -
1086 # return: pdf:STRING
1087 ###############
1088 sub generate_pdf {
1089 1 ▶ my $self = shift;
Subroutine generate_pdf: called CC=4 SCAR=20.3
Pod documented
1090  
1091 # save the env-var for restoring it later
1092 1 my $old_htmldoc_env = $ENV{'HTMLDOC_NOCGI'};
1093 1 $ENV{'HTMLDOC_NOCGI'} = 'yes';
1094  
1095 1 my $params = $self->_build_parameters();
1096 1 my $pdf;
1097  
1098 #if ($self->{'config'}->{'mode'} eq 'ipc') {
1099 1 ▶ if ($self->_config('mode') eq 'ipc') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_config('mode') eq 'ipc') { } 1 0 1
1100 # we are in normale Mode, use IPC
1101 1 my ($pid, $error);
1102 1 ($pid,$pdf,$error) = $self->_run($self->{'config'}->{'bindir'}."htmldoc $params --webpage -", $self->get_html_content());
1103 } else {
1104 # we are in file-mode
1105 0 my $filename = $self->_prepare_input_file();
1106 0 ▶ return undef if (!$filename);
Branch: 1 branch
BranchTrueFalseTotal
unless $filename 0 0 0
1107 0 $pdf = `$self->{'config'}->{'bindir'}htmldoc $params --webpage $filename`;
1108 0 $self->_cleanup();
1109 }
1110  
1111 # restore old value
1112 0 ▶ if (not defined $old_htmldoc_env) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $old_htmldoc_env) { } 0 0 0
1113 0 delete $ENV{'HTMLDOC_NOCGI'};
1114 } else {
1115 0 $ENV{'HTMLDOC_NOCGI'} = $old_htmldoc_env;
1116 }
1117  
1118 0 my $doc = new HTML::HTMLDoc::PDF(\$pdf);
1119  
1120 0 return $doc;
1121 }
1122  
1123 ###############
1124 # generates a string for the configuration of htmldoc
1125 # testet
1126 # param: -
1127 # return: params:STRING
1128 ###############
1129 sub _build_parameters {
1130 2 ▶ my $self = shift;
Subroutine _build_parameters: called CC=7 SCAR=22.7
1131  
1132 2 my $paramstring='';
1133  
1134 2 foreach my $key($self->_get_doc_config_keys()) {
1135 14 ▶ my $value = $self->_get_doc_config($key) || '';
Condition100%2/2
$self->_get_doc_config($key) || ''
l!l
104
MC/DC100%1/1
$self->_get_doc_config($key) || ''
$self->_get_doc_config($key)
Truth table100%2/2
A
A= $self->_get_doc_config($key)
Aresult
11
00
1136 14 ▶ if ( ref($value) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 14 14
1137 # an array, set the option multiple
1138 0 foreach my $single_v(@{$value}) {
1139 0 $paramstring .= " --$key $single_v";
1140 }
1141 } else {
1142 14 ▶ if ($key eq 'compression' || $key eq 'jpeg') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'compression' or $key eq 'jpeg') { } 0 14 14
Condition33%1/3
$key eq "compression" or $key eq "jpeg"
l!l&&r!l&&!r
0014
MC/DC0%0/2
$key eq "compression" or $key eq "jpeg"
$key eq "compression" $key eq "jpeg"
Truth table33%1/3
A or B
A= $key eq "compression"B= $key eq "jpeg"
ABresult
1X1
011
000
1143 0 $paramstring .= " --$key=$value";
1144 } else {
1145 14 $paramstring .= " --$key $value";
1146 }
1147 }
1148  
1149 }
1150  
1151 2 return $paramstring;
1152 }
1153  
1154 sub _run {
1155 1 ▶ my $self = shift;
Subroutine _run: called CC=3 SCAR=20.6
1156 1 my $command = shift;
1157 1 my $input = shift;
1158  
1159 # create new Filehandles
1160 1 my ($stdin,$stdout,$stderr) = (IO::Handle->new(),IO::Handle->new(),IO::Handle->new());
1161 1 my $pid = IPC::Open3::open3($stdin,$stdout,$stderr, $command);
1162 0 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 0 0 0
1163 0 $self->error("Cannot fork [COMMAND: '$command'].");
1164 0 return (0);
1165 }
1166  
1167 0 print $stdin $input;
1168 0 close $stdin;
1169  
1170 0 my $output = join('',<$stdout>);
1171 0 close $stdout;
1172  
1173 0 my $error = join('',<$stderr>);
1174 0 close $stderr;
1175  
1176 0 wait();
1177  
1178  
1179 0 ▶ if ($DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DEBUG) 0 0 0
1180 0 print STDERR "\n********************************************************************\n";
1181 0 print STDERR "COMMAND : \n$command [PID $pid]\n";
1182 0 print STDERR "STDIN : \n$input\n";
1183 0 print STDERR "STDOUT : \n$output\n";
1184 0 print STDERR "STDERR : \n$error\n";
1185 0 print STDERR "\n********************************************************************\n";
1186 }
1187  
1188 0 return($pid,$output,$error);
1189 }
1190  
1191 ###############
1192 # see the 'htmldoc' command which will be issued with their options
1193 # only works in file mode
1194 # param: -
1195 # return: 'htmldoc ...many arguments here...
1196 ###############
1197 sub get_htmldoc_command {
1198 0 ▶ my $self = shift;
Subroutine get_htmldoc_command: not called CC=3 SCAR=24.8
Pod documented
1199  
1200 0 ▶ if ($self->_config('mode') eq 'ipc') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_config("mode") eq "ipc") 0 0 0
1201 0 $self->error("get_htmldoc_command() only works in file mode.");
1202 0 return 0;
1203 }
1204  
1205 0 my $filename = $self->_prepare_input_file();
1206 0 ▶ if (!$filename) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filename) 0 0 0
1207 0 $self->error("Input filename not set.");
1208 0 return 0;
1209 }
1210  
1211 # build and return
1212 0 my $params = $self->_build_parameters();
1213  
1214 0 return $self->{'config'}->{'bindir'}.'htmldoc '.$params.' --webpage '.$filename.' > '.$filename.'.pdf';
1215  
1216 }
1217  
1218 ###############
1219 # set or retrieve an occurred error
1220 # param: -
1221 # return: pdf:STRING
1222 ###############
1223 sub error {
1224 11 ▶ my $self = shift;
Subroutine error: called CC=3 SCAR=11.3
Pod documented
1225 11 my $error = shift;
1226  
1227 11 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) { } 8 3 11
1228 8 push(@{$self->{'errors'}}, $error);
1229 } else {
1230 3 ▶ if (wantarray()) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 3 3
1231 0 return @{$self->{'errors'}};
1232 } else {
1233 3 return $self->{'errors'}->[0];
1234 }
1235 }
1236 }
1237  
1238 1 1;
1239 __END__
↑ Summary blib/lib/HTML/HTMLDoc/PDF.pm »