blib/lib/Linux/DVB/DVBT/Advert/Config.pm

filter: Statementstmt 38.2% 153 / 400 Branchbran 24.7% 56 / 226 Conditioncond 14.7% 13 / 88 MC/DCmcdc 5.8% 3 / 51 Subroutinesub 60.7% 17 / 28 Podpod 43.7% 7 / 16 totaltotal 30.7% 249 / 809 CC 167 SCAR 51.3
CC
167
Cov
31%
do_write_dvb_adv
506.0
BEGIN
388.9
write_dir
240.0
CRAP 168.7
« blib/lib/Linux/DVB/DVBT/Advert.pm ↑ Summary blib/lib/Linux/DVB/DVBT/Advert/Mem.pm »
1 package Linux::DVB::DVBT::Advert::Config ;
2
3 =head1 NAME
4
5 Linux::DVB::DVBT::Advert::Config - Advert detection config file
6
7 =head1 SYNOPSIS
8
9 use Linux::DVB::DVBT::Advert::Config ;
10
11
12 =head1 DESCRIPTION
13
14 This module provides the configuration file utilities for the advert detection and removal utilities.
15
16 =head2 Settings
17
18 Settings are passed into the routines via a HASH ref. Settings also come from the default set, and
19 from any config file parameters. The order of priority for these settings is:
20
21 =over 4
22
23 Default settings I<LOWEST priority>
24
25 Config file (Generic section)
26
27 Config file (Channel-specific section)
28
29 Settings used for detection
30
31 Settings HASH ref I<HIGHEST priority>
32
33 =back
34
35 Note that the "settings used for detection" only apply if the results from detection are saved in a file,
36 and then this file is read in for analysis (see L</Results Files>)
37
38 Settings are split between those that control the detection phase, and those that control the
39 analysis phase:
40
41 =head3 Detection Settings
42
43 Most of the detection settings (other than detection_method) can safely be left to their default values.
44
45
46 =over 4
47
48 =item B<detection_method>
49
50 Normally leave this set to the default (all methods used). Sometimes you may want to disable all advert detection (for non-commercial
51 channels), or possibly disable logo detection for channels that display a logo at all times.
52
53 This variable is actually a bitmap of flags: setting a bit enables the corresponding method. If you know what you want, you can specify
54 the variable as a decimal or hex value. It's recommended, however, to use the following symbols:
55
56 =over 4
57
58 =item I<disable>
59
60 Use this symbol on it's own to disable advert detection
61
62 =item I<default>
63
64 Use this symbol to specify the built-in default detection method (usually means use all methods)
65
66 =item I<black>
67
68 Black frame detection. This is where "black" (or dark) frames are expected to appear before and after advert
69 breaks.
70
71 =item I<logo>
72
73 Logo detection. This is where the channel logo is expected to be present during programs, but absent during adverts.
74
75 =item I<audio>
76
77 Silence (audio volume) detection. Quiet (or silent) periods are expected before and after adverts.
78
79 =back
80
81 The symbols above can be combined to specify the complete detection method. Use '+' or '-' before the
82 symbol to enable or disable the method respectively. Using a '+' or '-' before the first symbol specified,
83 results in the symbols being added/subtracted from the default set. Otherwise the set specified are used
84 to fully define the methods to use.
85
86 Example: "detection_method = logo + black" means to use only black frame and logo detection.
87
88 Example: "detection_method = -logo" means to use default detection methods but disable logo detection.
89
90 Example: "detection_method = disable" means to disable advert detection.
91
92
93 =item B<frame.schange_jump>
94
95 Black frame detection: sets the threshold for the step difference of scene score between frames for a scene change
96 to be detected.
97
98 =item B<frame.schange_cutlevel>
99
100 Black frame detection: scene change detection percentage above which is deemed a scene change frame
101
102 =item B<frame.max_black>
103
104 Black frame detection: maximum pixel value for the pixel to be determined as "black"
105
106 =item B<frame.max_brightness>
107
108 Black frame detection: maximum brightness percentage under which is treated as black
109
110 =item B<frame.brightness_jump>
111
112 Black frame detection: step difference of the brightness score between frames used to detect a black frame
113
114 =item B<frame.window_percent>
115
116 Black frame detection: percentage of frame to use for black frame detection (for example, setting this to 90% results
117 in 5% of the edges around the frame to be ignored)
118
119 =item B<frame.test_brightness>
120
121 Black frame detection: pixel value used for brightness detection
122
123 =item B<frame.noise_level>
124
125 Black frame detection: noise level used for black frame uniformity detection
126
127
128
129 =item B<logo.logo_edge_step>
130
131 Logo detection: Step size used for moving between pixels in all logo detection functions. For example, setting this to 2 skips
132 every other pixel, resulting in halving the amount of dtaa to process.
133
134 =item B<logo.logo_max_percentage_of_screen>
135
136 Logo detection: Once a logo has been possibly detected, this is a check to ensure that the area of the screen used by the logo
137 is no greater than this value. Otherwise the detected region cannot be a valid logo and is discarded.
138
139 =item B<logo.logo_window>
140
141 Logo detection: Number of image frames stored in a rolling detection buffer. The number of frames skipped between each stored frame is set by L</logo.logo_skip_frames>
142
143 =item B<logo.logo_skip_frames>
144
145 Logo detection: Number of frames to skip between used frames. This creates a bigger discrepancy between images and makes the logo
146 area easier to detect.
147
148 =item B<logo.logo_edge_threshold>
149
150 Logo detection: level used to decided whether this is a logo edge
151
152 =item B<logo.logo_ave_points>
153
154 Logo detection: The logo detection score is averaged over this number of frames.
155
156 =item B<logo.logo_checking_period>
157
158 Logo detection: maximum period (in frames) to use for detecting a logo. If a logo has not been found when we reach this number of frames
159 from the start of the video, then logo detection is cancelled.
160
161 =item B<logo.window_percent>
162
163 Logo detection: perecntage of total frame to use for logo detection
164
165 =item B<logo.logo_num_checks>
166
167 Logo detection: number of times a logo result is re-checked. Once a logo area is detected, the process is re-started this many times
168 to ensure we don't have a false detection.
169
170 =item B<logo.logo_ok_percent>
171
172 Logo detection: the logo detection score % must be above this value before a frame is flagged as containing a logo.
173
174 =item B<logo.logo_edge_radius>
175
176 Logo detection: number of pixels to use in logo edge detection
177
178
179 =item B<audio.silence_window>
180
181 Silence detection: adds "fuzziness" to detection of silence frames
182
183 =back
184
185
186 =head3 Analysis Settings
187
188 The analysis settings consist of a global set of settings that are used in all cases. Also, each detection mode (black frame, logo etc)
189 has it's own set of settings that may be set to over-ride the global set. In the same manner as the detection settings, each set if prefixed
190 by it's own namespace (e.g. for black frame detection use 'frame.' etc).
191
192 =over 4
193
194 =item B<max_advert>
195
196 The maximum length of a single advert (in frames). Multiple adverts may be joined to form the total advert/commercial break between
197 program sections.
198
199 =item B<min_advert>
200
201 The minimum length of a single advert (in frames).
202
203 =item B<min_program>
204
205 The minimum length (in frames) of a section of program.
206
207 =item B<start_pad>
208
209 (UNUSED) Expected amount of padding (in frames) before the start of a program recording.
210
211 =item B<end_pad>
212
213 (UNUSED) Expected amount of padding (in frames) at the start of a program recording.
214
215 =item B<min_frames>
216
217 Minimum number of frames to be contracted into a block.
218
219 =item B<frame_window>
220
221 fuzziness window when contracting frames into a block
222
223 =item B<max_gap>
224
225 widest gap (no valid frames) over which to span when contracting frames into a block
226
227 =item B<reduce_end>
228
229 window (in frames) in which to reduce the end of the program to the nearest gap
230
231 =item B<reduce_min_gap>
232
233 frame gap used for reducing program end point
234
235
236 =back
237
238 Black frame settings (see above to descriptions):
239
240 =over 4
241
242 =item B<frame.max_advert>
243
244 =item B<frame.min_advert>
245
246 =item B<frame.min_program>
247
248 =item B<frame.start_pad>
249
250 =item B<frame.end_pad>
251
252 =item B<frame.min_frames>
253
254 =item B<frame.frame_window>
255
256 =item B<frame.max_gap>
257
258 =item B<frame.reduce_end>
259
260 =item B<frame.reduce_min_gap>
261
262 =item B<frame.increase_start>
263
264 =item B<frame.increase_min_gap>
265
266 =back
267
268 Logo frame settings (see above to descriptions):
269
270 =over 4
271
272 =item B<logo.max_advert>
273
274 =item B<logo.min_advert>
275
276 =item B<logo.min_program>
277
278 =item B<logo.start_pad>
279
280 =item B<logo.end_pad>
281
282 =item B<logo.min_frames>
283
284 =item B<logo.frame_window>
285
286 =item B<logo.max_gap>
287
288 =item B<logo.reduce_end>
289
290 =item B<logo.reduce_min_gap>
291
292 =item B<logo.increase_start>
293
294 =item B<logo.increase_min_gap>
295
296 =item B<logo.logo_rise_threshold>
297
298 =item B<logo.logo_fall_threshold>
299
300 =back
301
302 Silence frame settings (see above to descriptions):
303
304 =over 4
305
306 =item B<audio.max_advert>
307
308 =item B<audio.min_advert>
309
310 =item B<audio.min_program>
311
312 =item B<audio.start_pad>
313
314 =item B<audio.end_pad>
315
316 =item B<audio.min_frames>
317
318 =item B<audio.frame_window>
319
320 =item B<audio.max_gap>
321
322 =item B<audio.reduce_end>
323
324 =item B<audio.reduce_min_gap>
325
326 =item B<audio.increase_start>
327
328 =item B<audio.increase_min_gap>
329
330 =back
331
332 =head2 Config File
333
334 The configuration file is of the form:
335
336 # global settings
337 detection_method = 15
338 frame.max_black = 48
339 frame.window_percent = 95
340 frame.max_brightness = 60
341 frame.test_brightness = 40
342 frame.brightness_jump = 200
343 frame.schange_cutlevel = 85
344 frame.schange_jump = 30
345 frame.noise_level = 5
346 logo.window_percent = 95
347 logo.logo_window = 50
348 logo.logo_edge_radius = 2
349 logo.logo_edge_step = 1
350 logo.logo_edge_threshold = 5
351 logo.logo_checking_period = 30000
352 logo.logo_skip_frames = 25
353 logo.logo_num_checks = 5
354 logo.logo_ok_percent = 80
355 logo.logo_max_percentage_of_screen = 10
356 logo.logo_ave_points = 250
357 audio.scale = 1
358 audio.silence_threshold = -80
359
360 # Channel-specific settings
361 [Dave]
362 logo.logo_skip_frames = 30
363 logo.logo_num_checks = 2
364 logo.logo_ok_percent = 85
365
366
367 =head2 Config File Search Path
368
369 Some of the functions (for example L</read_dvb_adv( [$search_path] )>) accept an optional search path. If this is specified then the same
370 search path will be used from that point on (until a different search path is specified).
371
372 By default, the search path is set to attempt to match with L<Linux::DVB::DVBT> on those platforms that support that path; otherwise
373 the user's home directory is used.
374
375 Setting the search path allows the module to attempt to read/write the configuration file from multiple directories. This allows there to
376 be a common global file used by all users, but each user may then create their own configuration file to over ride the global one however
377 they choose.
378
379 The format for the search path is an ARRAY ref list of directories, for example:
380
381 [ '/etc/dvb', '~/.tv' ]
382
383 or
384
385 [ 'c:\tv', 'd:\profiles\user\tv' ]
386
387
388 =cut
389
390
391 12 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
392 12 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
393
394 12 ▶use File::Spec ;
Subroutine BEGIN: called CC=1 SCAR=0.0
395 12 ▶use Data::Dumper ;
Subroutine BEGIN: called CC=1 SCAR=0.0
396
397 12 ▶use Linux::DVB::DVBT::Advert::Constants ;
Subroutine BEGIN: called CC=1 SCAR=0.0
398
399 12 our $VERSION = '1.03' ;
400 12 our $DEBUG = 0 ;
401
402 12 our $DEFAULT_CONFIG_PATH ;
403 12 our $FILENAME = 'dvb-adv' ;
404
405 12 my %NUMERALS = (
406 'one' => 1,
407 'two' => 2,
408 'three' => 3,
409 'four' => 4,
410 'five' => 5,
411 'six' => 6,
412 'seven' => 7,
413 'eight' => 8,
414 'nine' => 9,
415 ) ;
416
417
418 #============================================================================================
419 12 our $ADVERT_GLOBAL_SECTION = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA__GLOBAL__" ;
420 12 our $METHOD_VAR = "detection_method" ;
421 12 our $METHOD_DISABLE = "disable" ;
422 12 our $METHOD_DISABLE_REGEXP = "none|$METHOD_DISABLE" ;
423
424 12 my %SETTINGS_COMMENTS = (
425
426 'max_advert' => 'maximum length of a single advert (in frames)',
427 'min_advert' => 'minimum length of advert period (cut period) excludes prog change (in frames)',
428 'min_program' => 'minimum length of a program (in frames)',
429 'start_pad' => 'padding at start of recording (in frames)',
430 'end_pad' => 'padding at end of recording (in frames)',
431 'min_frames' => 'minimum number of frames to be contracted into a block',
432 'frame_window' => 'fuzziness window when contracting frames into a block',
433 'max_gap' => 'widest gap (no valid frames) over which to span when contracting frames into a block',
434 'reduce_end' => 'window (in frames) in which to reduce the end of the program to the nearest gap',
435 'reduce_min_gap' => 'frame gap used for reducing program end point',
436 'detection_method' => 'advert detection method specified numerically or in symbols e.g. logo+black',
437
438 'logo.logo_edge_step' => 'pixel step size for logo detection',
439 'logo.logo_window' => 'number of frames stored in the logo detection buffer',
440 'logo.logo_max_percentage_of_screen' => 'maximum size of a logo (anything larger is discarded)',
441 'logo.logo_skip_frames' => 'number of frames to skip between logo detection',
442 'logo.logo_edge_threshold' => 'level used to decided whether this is a logo edge',
443 'logo.logo_ave_points' => 'logo averaging buffer size',
444 'logo.logo_checking_period' => 'maximum period (in frames) to use for detecting a logo',
445 'logo.window_percent' => 'percentage of frame to use for detection',
446 'logo.logo_num_checks' => 'number of logo re-checks',
447 'logo.logo_ok_percent' => 'percentage over which logo detection is deemed a match',
448 'logo.logo_edge_radius' => 'number of pixels to use in logo edge detection',
449 'logo.logo_rise_threshold' => 'percentage over which logo detection is deemed a match : going from non-logo to logo frames',
450 'logo.logo_fall_threshold' => 'percentage over which logo detection is deemed a match : going from logo to non-logo frames',
451
452 'frame.schange_jump' => 'sceen change detection level step',
453 'frame.schange_cutlevel' => 'scene change detection percentage above which is deemed a scene change frame',
454 'frame.max_black' => 'maximum pixel value under which pixel is treated as black',
455 'frame.max_brightness' => 'maximum brightness percentage under which is treated as black',
456 'frame.brightness_jump' => 'difference level between frames used to detect a black frame',
457 'frame.window_percent' => 'percentage of frame to use for detection',
458 'frame.test_brightness' => 'pixel value used for brightness detection',
459 'frame.noise_level' => 'noise level used for black frame uniformity detection',
460
461 'audio.silence_window' => 'adds "fuzziness" to detection of silence frames',
462
463 ) ;
464
465
466 12 my @SETTINGS_REGIONS = (
467 'global', 'frame', 'logo', 'audio',
468 ) ;
469 12 my %SETTINGS_TEMPLATE = (
470
471 'global' => [
472 '# ------------------------------------------------',
473 '# Global settings.',
474 '#',
475 '# Any settings here propagate down any unset ',
476 '# detection-specific settings',
477 '# ------------------------------------------------',
478 '',
479 '# -- Settings used by detection algorithms (XS) --',
480 '',
481 'detection_method',
482 '',
483 '# -- Settings used by analysis algorithms (Perl) --',
484 '',
485 'max_advert',
486 'min_advert',
487 'min_program',
488 'start_pad',
489 'end_pad',
490 'min_frames',
491 'frame_window',
492 'max_gap',
493 'reduce_end',
494 'reduce_min_gap',
495 'increase_start',
496 'increase_min_gap',
497 '',
498 ],
499
500 'frame' => [
501 '# ------------------------------------------------',
502 '# Frame detection specific settings.',
503 '# ------------------------------------------------',
504 '',
505 '# -- Settings used by detection algorithms (XS) --',
506 '',
507 'frame.schange_jump',
508 'frame.schange_cutlevel',
509 'frame.max_black',
510 'frame.max_brightness',
511 'frame.brightness_jump',
512 'frame.window_percent',
513 'frame.test_brightness',
514 'frame.noise_level',
515 '',
516 '# -- Settings used by analysis algorithms (Perl) --',
517 '',
518 'frame.max_advert',
519 'frame.min_advert',
520 'frame.min_program',
521 'frame.start_pad',
522 'frame.end_pad',
523 'frame.min_frames',
524 'frame.frame_window',
525 'frame.max_gap',
526 'frame.reduce_end',
527 'frame.reduce_min_gap',
528 'frame.increase_start',
529 'frame.increase_min_gap',
530 '',
531 ],
532
533 'logo' => [
534 '# ------------------------------------------------',
535 '# Logo detection specific settings.',
536 '# ------------------------------------------------',
537 '',
538 '# -- Settings used by detection algorithms (XS) --',
539 '',
540 'logo.logo_edge_step',
541 'logo.logo_max_percentage_of_screen',
542 'logo.logo_window',
543 'logo.logo_skip_frames',
544 'logo.logo_edge_threshold',
545 'logo.logo_ave_points',
546 'logo.logo_checking_period',
547 'logo.window_percent',
548 'logo.logo_num_checks',
549 'logo.logo_ok_percent',
550 'logo.logo_edge_radius',
551 '',
552 '# -- Settings used by analysis algorithms (Perl) --',
553 '',
554 'logo.max_advert',
555 'logo.min_advert',
556 'logo.min_program',
557 'logo.start_pad',
558 'logo.end_pad',
559 'logo.min_frames',
560 'logo.frame_window',
561 'logo.max_gap',
562 'logo.reduce_end',
563 'logo.reduce_min_gap',
564 'logo.increase_start',
565 'logo.increase_min_gap',
566 'logo.logo_rise_threshold',
567 'logo.logo_fall_threshold',
568 '',
569 ],
570
571 'audio' => [
572 '# ------------------------------------------------',
573 '# Audio detection specific settings.',
574 '# ------------------------------------------------',
575 '',
576 '# -- Settings used by detection algorithms (XS) --',
577 '',
578 'audio.silence_window',
579 '',
580 '# -- Settings used by analysis algorithms (Perl) --',
581 '',
582 'audio.max_advert',
583 'audio.min_advert',
584 'audio.min_program',
585 'audio.start_pad',
586 'audio.end_pad',
587 'audio.min_frames',
588 'audio.frame_window',
589 'audio.max_gap',
590 'audio.reduce_end',
591 'audio.reduce_min_gap',
592 'audio.increase_start',
593 'audio.increase_min_gap',
594 '',
595 ],
596 ) ;
597
598
599 #============================================================================================
600 12 ▶BEGIN {
Subroutine BEGIN: called CC=24 SCAR=59.6
601
602 ## Default for Linux::DVB::DVBT
603 12 $DEFAULT_CONFIG_PATH = [ qw(/etc/dvb ~/.tv) ] ;
604
605 12 my $home ;
606 12 ▶ if ( exists $ENV{HOME} and defined $ENV{HOME} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"HOME"} and defined $ENV{"HOME"}) 12 0 12
Condition33%1/3
exists $ENV{"HOME"} and defined $ENV{"HOME"}
!ll&&!rl&&r
0012
MC/DC0%0/2
exists $ENV{"HOME"} and defined $ENV{"HOME"}
exists $ENV{"HOME"} defined $ENV{"HOME"}
Truth table33%1/3
A and B
A= exists $ENV{"HOME"}B= defined $ENV{"HOME"}
ABresult
0X0
100
111
607 {
608 12 $home = $ENV{HOME};
609 }
610
611 ## Check OS
612 12 ▶ if ( $^O eq 'MSWin32' )
Branch: 4 branches
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 12 12
elsif ($^O eq 'darwin') { } 0 12 12
elsif ($^O eq 'MacOS') { } 0 12 12
elsif ($^O eq 'linux' or $^O eq 'cygwin') { } 12 0 12
613 {
614 # All versions of Windows
615
616 # Do we have a user profile?
617 0 ▶ if ( !$home && exists $ENV{USERPROFILE} && $ENV{USERPROFILE} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $home and exists $ENV{"USERPROFILE"} and $ENV{"USERPROFILE"}) 0 0 0
Condition0%0/6
not $home and exists $ENV{"USERPROFILE"} and $ENV{"USERPROFILE"}
!ll&&!rl&&r
000
not $home and exists $ENV{"USERPROFILE"}
!ll&&!rl&&r
000
MC/DC0%0/3
not $home and exists $ENV{"USERPROFILE"} and $ENV{"USERPROFILE"}
not $home exists $ENV{"USERPROFILE"} $ENV{"USERPROFILE"}
Truth table0%0/4
not(A) and B and C
A= not $homeB= exists $ENV{"USERPROFILE"}C= $ENV{"USERPROFILE"}
ABCresult
0XX0
10X0
1100
1111
618 {
619 0 $home = $ENV{USERPROFILE};
620 }
621
622 # Some Windows use something like $ENV{HOME}
623 0 ▶ if ( !$home && exists $ENV{HOMEDRIVE} && exists $ENV{HOMEPATH} && $ENV{HOMEDRIVE} && $ENV{HOMEPATH} )
Branch: 1 branch
BranchTrueFalseTotal
if (not $home and exists $ENV{"HOMEDRIVE"} and exists $ENV{"HOMEPATH"} and $ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"}) 0 0 0
Condition0%0/12
not $home and exists $ENV{"HOMEDRIVE"} and exists $ENV{"HOMEPATH"} and $ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"}
!ll&&!rl&&r
000
not $home and exists $ENV{"HOMEDRIVE"} and exists $ENV{"HOMEPATH"} and $ENV{"HOMEDRIVE"}
!ll&&!rl&&r
000
not $home and exists $ENV{"HOMEDRIVE"} and exists $ENV{"HOMEPATH"}
!ll&&!rl&&r
000
not $home and exists $ENV{"HOMEDRIVE"}
!ll&&!rl&&r
000
MC/DC0%0/5
not $home and exists $ENV{"HOMEDRIVE"} and exists $ENV{"HOMEPATH"} and $ENV{"HOMEDRIVE"} and $ENV{"HOMEPATH"}
not $home exists $ENV{"HOMEDRIVE"} exists $ENV{"HOMEPATH"} $ENV{"HOMEDRIVE"} $ENV{"HOMEPATH"}
Truth table0%0/6
not(A) and B and C and D and E
A= not $homeB= exists $ENV{"HOMEDRIVE"}C= exists $ENV{"HOMEPATH"}D= $ENV{"HOMEDRIVE"}E= $ENV{"HOMEPATH"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
624 {
625 0 $home = File::Spec->catpath($ENV{HOMEDRIVE}, $ENV{HOMEPATH}, '');
626 }
627
628 0 $DEFAULT_CONFIG_PATH = [] ;
629 0 ▶ if ($home && -d $home)
Branch: 1 branch
BranchTrueFalseTotal
if ($home and -d $home) 0 0 0
Condition0%0/3
$home and -d $home
!ll&&!rl&&r
000
MC/DC0%0/2
$home and -d $home
$home -d $home
Truth table0%0/3
A and B
A= $homeB= -d $home
ABresult
0X0
100
111
630 {
631 0 $home =~ s%\\%/%g ;
632 0 push @$DEFAULT_CONFIG_PATH, "$home/tv" ;
633 }
634
635 # add current dir
636 0 push @$DEFAULT_CONFIG_PATH, "." ;
637 }
638 elsif ( $^O eq 'darwin')
639 {
640 0 ▶ if (!$home)
Branch: 1 branch
BranchTrueFalseTotal
unless ($home) 0 0 0
641 {
642 0 $home = (getpwuid($<))[7];
643 }
644
645 0 $DEFAULT_CONFIG_PATH = [] ;
646 0 ▶ if ($home && -d $home)
Branch: 1 branch
BranchTrueFalseTotal
if ($home and -d $home) 0 0 0
Condition0%0/3
$home and -d $home
!ll&&!rl&&r
000
MC/DC0%0/2
$home and -d $home
$home -d $home
Truth table0%0/3
A and B
A= $homeB= -d $home
ABresult
0X0
100
111
647 {
648 0 push @$DEFAULT_CONFIG_PATH, "$home/tv" ;
649 }
650
651 # add current dir
652 0 push @$DEFAULT_CONFIG_PATH, "." ;
653 }
654 elsif ( $^O eq 'MacOS' )
655 {
656 0 ▶ if (!$home)
Branch: 1 branch
BranchTrueFalseTotal
unless ($home) 0 0 0
657 {
658 # On some platforms getpwuid dies if called at all
659 0 local $SIG{'__DIE__'} = '';
660 0 $home = (getpwuid($<))[7];
661 }
662
663 0 $DEFAULT_CONFIG_PATH = [] ;
664 0 ▶ if ($home && -d $home)
Branch: 1 branch
BranchTrueFalseTotal
if ($home and -d $home) 0 0 0
Condition0%0/3
$home and -d $home
!ll&&!rl&&r
000
MC/DC0%0/2
$home and -d $home
$home -d $home
Truth table0%0/3
A and B
A= $homeB= -d $home
ABresult
0X0
100
111
665 {
666 0 push @$DEFAULT_CONFIG_PATH, "$home/tv" ;
667 }
668
669 # add current dir
670 0 push @$DEFAULT_CONFIG_PATH, "." ;
671 }
672 ▶ elsif ( ($^O eq 'linux') || ($^O eq 'cygwin') )
Condition33%1/3
$^O eq "linux" or $^O eq "cygwin"
l!l&&r!l&&!r
1200
MC/DC0%0/2
$^O eq "linux" or $^O eq "cygwin"
$^O eq "linux" $^O eq "cygwin"
Truth table33%1/3
A or B
A= $^O eq "linux"B= $^O eq "cygwin"
ABresult
1X1
011
000
673 {
674 # Default to Linux::DVB::DVBT
675 }
676 else
677 {
678 # Default to Unix semantics
679 0 $DEFAULT_CONFIG_PATH = [ qw(/etc/dvb ~/.tv .) ] ;
680 }
681
682
683
684 #print "Search Path:\n" ;
685 #foreach (@$DEFAULT_CONFIG_PATH)
686 #{
687 # print " $_\n" ;
688 #}
689
690
691 }
692
693
694
695 #============================================================================================
696
697 =head2 Functions
698
699 =over 4
700
701 =cut
702
703
704 #----------------------------------------------------------------------
705
706 =item B<read_dvb_adv( [$search_path] )>
707
708 Read the advert settings file and return a HASH ref containing the settings.
709
710 Optionally set the search path (see L</Config File Search Path>)
711
712 See L</Config File>
713
714 =cut
715
716 sub read_dvb_adv
717 5 ▶{
Subroutine read_dvb_adv: called CC=8 SCAR=20.8
Pod documented
718 5 my ($search_path) = @_ ;
719
720 5 ▶ $search_path ||= $DEFAULT_CONFIG_PATH ;
Condition33%1/3
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
l!l&&r!l&&!r
500
MC/DC0%0/2
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
$search_path $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
Truth table33%1/3
A ||= B
A= $search_pathB= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
ABresult
1X1
011
000
721 5 $DEFAULT_CONFIG_PATH = $search_path ;
722
723 5 my $adv_settings_href = {
724 "$ADVERT_GLOBAL_SECTION" => {},
725 } ;
726
727 ## Optional file so allow for it to be not present
728 5 my @fnames = read_filenames($search_path) ;
729 5 foreach my $fname (@fnames)
730 {
731 6 my %dvb_adv = (
732 "$ADVERT_GLOBAL_SECTION" => {},
733 ) ;
734 6 ▶ if (open my $fh, "<$fname")
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "<$fname") 5 1 6
735 {
736 5 my $line ;
737 5 my $channel = $ADVERT_GLOBAL_SECTION ;
738 5 ▶ while(defined($line=<$fh>))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 1074 5 1079
739 {
740 1074 chomp $line ;
741 1074 ▶ next if $line =~ /^\s*#/ ; # skip comments
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*#/ 606 468 1074
742
743 468 ▶ if ($line =~ /\[([^]]+)\]/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /\[([^]]+)\]/) { } 16 452 468
744 {
745 16 $channel=$1;
746 }
747 else
748 {
749 452 ▶ $dvb_adv{$channel} ||= {} ;
Condition100%2/2
$dvb_adv{$channel} ||= {}
l!l
43616
MC/DC100%1/1
$dvb_adv{$channel} ||= {}
$dvb_adv{$channel}
Truth table100%2/2
A
A= $dvb_adv{$channel}
Aresult
11
00
750 452 parse_assignment($line, $dvb_adv{$channel}) ;
751 }
752 }
753 5 close $fh ;
754
755 # combine
756 5 $adv_settings_href = Linux::DVB::DVBT::Advert::Config::merge_settings(
757 $adv_settings_href,
758 \%dvb_adv,
759 ) ;
760 }
761
762 }
763
764 5 return $adv_settings_href ;
765 }
766
767
768 #----------------------------------------------------------------------
769
770 =item B<write_dvb_adv($href [, $search_path])>
771
772 Write advert config information
773
774 Optionally set the search path (see L</Config File Search Path>)
775
776 =cut
777
778 sub write_dvb_adv
779 0 ▶{
Subroutine write_dvb_adv: not called CC=2 SCAR=17.9
Pod documented
780 0 my ($href, $search_path) = @_ ;
781
782 0 ▶ $search_path ||= $DEFAULT_CONFIG_PATH ;
Condition0%0/3
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
l!l&&r!l&&!r
000
MC/DC0%0/2
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
$search_path $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
Truth table0%0/3
A ||= B
A= $search_pathB= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
ABresult
1X1
011
000
783 0 $DEFAULT_CONFIG_PATH = $search_path ;
784
785 ## write settings
786 0 do_write_dvb_adv(write_filename($search_path), $href) ;
787 }
788
789 #----------------------------------------------------------------------
790
791 =item B<write_filename([$search_path])>
792
793 Returns the advert config file writeable filename path
794
795 Optionally set the search path (see L</Config File Search Path>)
796
797 =cut
798
799 sub write_filename
800 0 ▶{
Subroutine write_filename: not called CC=2 SCAR=17.9
Pod documented
801 0 my ($search_path) = @_ ;
802
803 0 ▶ $search_path ||= $DEFAULT_CONFIG_PATH ;
Condition0%0/3
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
l!l&&r!l&&!r
000
MC/DC0%0/2
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
$search_path $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
Truth table0%0/3
A ||= B
A= $search_pathB= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
ABresult
1X1
011
000
804 0 $DEFAULT_CONFIG_PATH = $search_path ;
805
806 0 my $dir = write_dir($search_path, $FILENAME) ;
807
808 0 return "$dir/$FILENAME" ;
809 }
810
811 #----------------------------------------------------------------------
812
813 =item B<read_filenames([$search_path])>
814
815 Returns an array of found file paths for all readable advert config files found in search path
816
817 Optionally set the search path (see L</Config File Search Path>)
818
819 =cut
820
821 sub read_filenames
822 5 ▶{
Subroutine read_filenames: called CC=5 SCAR=16.8
Pod documented
823 5 my ($search_path) = @_ ;
824
825 5 ▶ $search_path ||= $DEFAULT_CONFIG_PATH ;
Condition33%1/3
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
l!l&&r!l&&!r
500
MC/DC0%0/2
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
$search_path $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
Truth table33%1/3
A ||= B
A= $search_pathB= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
ABresult
1X1
011
000
826 5 $DEFAULT_CONFIG_PATH = $search_path ;
827
828 5 my @files = read_dir($search_path, $FILENAME) ;
829 5 ▶print "read_filenames() dirs=@files\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 5 0 5
830 5 foreach my $file (@files)
831 {
832 6 $file .= "/$FILENAME" ;
833 }
834
835 5 ▶print "read_filenames() = @files\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 5 0 5
836
837 5 return @files ;
838 }
839
840 #----------------------------------------------------------------------
841
842 =item B<write_default_dvb_adv($href [, $search_path])>
843
844 Write a default advert config information file
845
846 Optionally set the search path (see L</Config File Search Path>)
847
848 =cut
849
850 sub write_default_dvb_adv
851 0 ▶{
Subroutine write_default_dvb_adv: not called CC=9 SCAR=45.0
Pod documented
852 0 my ($href, $search_path) = @_ ;
853
854 0 ▶ $search_path ||= $DEFAULT_CONFIG_PATH ;
Condition0%0/3
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
l!l&&r!l&&!r
000
MC/DC0%0/2
$search_path ||= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
$search_path $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
Truth table0%0/3
A ||= B
A= $search_pathB= $Linux::DVB::DVBT::Advert::Config::DEFAULT_CONFIG_PATH
ABresult
1X1
011
000
855 0 $DEFAULT_CONFIG_PATH = $search_path ;
856
857 # Add some example settings
858 0 my $settings_href = { %$href } ;
859 0 $settings_href->{'Dave'} = {
860 'reduce_end' => 900,
861 'reduce_min_gap' => 50,
862 } ;
863 0 $settings_href->{'BBC1'} = {
864 'detection_method' => 'disable',
865 } ;
866 0 $settings_href->{'BBC2'} = {
867 'detection_method' => 'disable',
868 } ;
869 # $settings_href->{'BBC3'} = {
870 # 'detection_method' => 'disable',
871 # } ;
872 # $settings_href->{'BBC4'} = {
873 # 'detection_method' => 'disable',
874 # } ;
875 0 $settings_href->{'Virgin1'} = {
876 'detection_method' => 'disable',
877 } ;
878
879 0 ▶print Data::Dumper->Dump(["write_default_dvb_adv() settings:", $href]) if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
880
881 # comment everything EXCEPT detection_method
882 0 my $commented_href = {} ;
883
884 0 foreach my $section (keys %$settings_href)
885 {
886 0 foreach my $field (sort keys %{$href->{$section}})
887 {
888 0 my $val = $href->{$section}{$field} ;
889 0 ▶ if (ref($val) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'HASH') { } 0 0 0
890 {
891 0 foreach my $subvar (sort keys %{$val})
892 {
893 0 ▶ next if $subvar eq $METHOD_VAR ;
Branch: 1 branch
BranchTrueFalseTotal
if $subvar eq $Linux::DVB::DVBT::Advert::Config::METHOD_VAR 0 0 0
894 0 $commented_href->{$section}{$field}{$subvar} = 1 ;
895 }
896 }
897 else
898 {
899 0 ▶ next if $field eq $METHOD_VAR ;
Branch: 1 branch
BranchTrueFalseTotal
if $field eq $Linux::DVB::DVBT::Advert::Config::METHOD_VAR 0 0 0
900 0 $commented_href->{$section}{$field} = 1 ;
901 }
902 }
903 }
904
905 ## write example settings
906 0 do_write_dvb_adv(write_filename($search_path), $settings_href, $commented_href) ;
907 }
908
909
910 # ============================================================================================
911 # PROTECTED
912
913 #----------------------------------------------------------------------
914 # Uses optional $commented_href which comments out any matching elements
915 # This is only used for writing default config files (i.e. allows for
916 # commented examples)
917 #
918 sub do_write_dvb_adv
919 0 ▶{
Subroutine do_write_dvb_adv: not called CC=22 SCAR=62.3
Pod undocumented
920 0 my ($fname, $href, $commented_href) = @_ ;
921
922 0 ▶ $commented_href ||= {} ;
Condition0%0/2
$commented_href ||= {}
l!l
00
MC/DC0%0/1
$commented_href ||= {}
$commented_href
Truth table0%0/2
A
A= $commented_href
Aresult
11
00
923
924 0 ▶ open my $fh, ">$fname" or die "Error: Unable to write $fname : $!" ;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">$fname" or die "Error: Unable to write $fname : $!" 0 0 0
925
926 # Write config information
927 #
928
929 ## Global first then channel specific (sort automatically picks global key first)
930 0 my %seen ;
931 0 foreach my $section (sort keys %$href)
932 {
933 0 ▶ if ($section ne $ADVERT_GLOBAL_SECTION)
Branch: 1 branch
BranchTrueFalseTotal
if ($section ne $Linux::DVB::DVBT::Advert::Config::ADVERT_GLOBAL_SECTION) { } 0 0 0
934 {
935 0 print $fh "\n\n" ;
936 0 print $fh "# ====================================================================\n" ;
937 0 print $fh "# $section channel-specific settings\n" ;
938 0 print $fh "# ====================================================================\n" ;
939 0 print $fh "[$section]\n" ;
940 }
941 else
942 {
943 0 print $fh "\n\n" ;
944 0 print $fh "# ====================================================================\n" ;
945 0 print $fh "# Global settings\n" ;
946 0 print $fh "# \n" ;
947 0 print $fh "# (These settings propagate to any unset channel-specific settings)\n" ;
948 0 print $fh "# ====================================================================\n" ;
949 }
950 0 print $fh "\n\n" ;
951
952 0 ▶ $seen{$section} ||= {} ;
Condition0%0/2
$seen{$section} ||= {}
l!l
00
MC/DC0%0/1
$seen{$section} ||= {}
$seen{$section}
Truth table0%0/2
A
A= $seen{$section}
Aresult
11
00
953
954 ## Drive output from template
955 0 for my $region (@SETTINGS_REGIONS)
956 {
957 0 my $buffer = "" ;
958 0 my $clear_buffer = 0 ;
959
960 0 foreach my $line (@{$SETTINGS_TEMPLATE{$region}})
961 {
962 0 ▶ if (!$line || ($line =~ /#/))
Branch: 1 branch
BranchTrueFalseTotal
if (not $line or $line =~ /#/) { } 0 0 0
Condition0%0/3
not $line or $line =~ /#/
l!l&&r!l&&!r
000
MC/DC0%0/2
not $line or $line =~ /#/
not $line $line =~ /#/
Truth table0%0/3
not(A) or B
A= not $lineB= $line =~ /#/
ABresult
1X1
011
000
963 {
964 0 ▶ $buffer = "" if $clear_buffer ;
Branch: 1 branch
BranchTrueFalseTotal
if $clear_buffer 0 0 0
965 0 $buffer .= "$line\n" ;
966 }
967 else
968 {
969 # this is a variable
970 0 ++$clear_buffer ;
971 0 my $printed = 0 ;
972 0 my ($field, $subvar) = _field_parse($line) ;
973 0 my $comment = _lookup_comment($field, $subvar) ;
974
975 0 my $val = $href->{$section}{$field} ;
976 0 ▶ if ($subvar)
Branch: 1 branch
BranchTrueFalseTotal
if ($subvar) { } 0 0 0
977 {
978 0 ▶ if (exists($val->{$subvar}) && defined($val->{$subvar}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $val->{$subvar} and defined $val->{$subvar}) 0 0 0
Condition0%0/3
exists $val->{$subvar} and defined $val->{$subvar}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $val->{$subvar} and defined $val->{$subvar}
exists $val->{$subvar} defined $val->{$subvar}
Truth table0%0/3
A and B
A= exists $val->{$subvar}B= defined $val->{$subvar}
ABresult
0X0
100
111
979 {
980 0 print $fh $buffer ;
981 0 ++$printed ;
982
983 0 ▶ print $fh "# $comment\n" if $comment ;
Branch: 1 branch
BranchTrueFalseTotal
if $comment 0 0 0
984 0 ▶ print $fh "#" if ($commented_href->{$section}{$field}{$subvar}) ;
Branch: 1 branch
BranchTrueFalseTotal
if $commented_href->{$section}{$field}{$subvar} 0 0 0
985 0 print $fh "$field.$subvar = $val->{$subvar}\n" ;
986 }
987
988 0 ▶ $seen{$section}{$field} ||= {} ;
Condition0%0/2
$seen{$section}{$field} ||= {}
l!l
00
MC/DC0%0/1
$seen{$section}{$field} ||= {}
$seen{$section}{$field}
Truth table0%0/2
A
A= $seen{$section}{$field}
Aresult
11
00
989 0 $seen{$field}{$subvar} = 1 ;
990 }
991 else
992 {
993 0 ▶ if (defined($val))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 0 0 0
994 {
995 0 print $fh $buffer ;
996 0 ++$printed ;
997
998 0 ▶ print $fh "# $comment\n" if $comment ;
Branch: 1 branch
BranchTrueFalseTotal
if $comment 0 0 0
999 0 ▶ print $fh "#" if ($commented_href->{$section}{$field}) ;
Branch: 1 branch
BranchTrueFalseTotal
if $commented_href->{$section}{$field} 0 0 0
1000
1001 0 ▶ if ($field eq $METHOD_VAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($field eq $Linux::DVB::DVBT::Advert::Config::METHOD_VAR) { } 0 0 0
1002 {
1003 0 my $str = method_string($val) ;
1004 0 print $fh "$field = $str\n" ;
1005 }
1006 else
1007 {
1008 0 print $fh "$field = $val\n" ;
1009 }
1010 }
1011 0 $seen{$section}{$field} = 1 ;
1012 }
1013
1014 0 ▶ if ($printed)
Branch: 1 branch
BranchTrueFalseTotal
if ($printed) 0 0 0
1015 {
1016 0 print $fh "\n" ;
1017 0 $buffer = "" ;
1018 }
1019 }
1020 }
1021
1022 # ## Catch any "unseen" (i.e. I've forgotten to update the templates!)
1023 # foreach my $field (sort keys %{$href->{$section}})
1024 # {
1025 # my $val = $href->{$section}{$field} ;
1026 # if (ref($val) eq 'HASH')
1027 # {
1028 # foreach my $subvar (sort keys %{$val})
1029 # {
1030 # next if ($seen{$section}{$field}{$subvar}) ;
1031 # print $fh "$field.$subvar = $val->{$subvar}\n" ;
1032 # }
1033 # }
1034 # else
1035 # {
1036 # next if ($seen{$section}{$field}) ;
1037 #
1038 # if ($field eq $METHOD_VAR)
1039 # {
1040 # my $str = method_string($val) ;
1041 # print $fh "$field = $str\n" ;
1042 # }
1043 # else
1044 # {
1045 # if ($val =~ /\S+/)
1046 # {
1047 # print $fh "$field = $val\n" ;
1048 # }
1049 # }
1050 # }
1051 # }
1052 }
1053
1054 0 print $fh "\n" ;
1055 }
1056
1057 0 close $fh ;
1058 }
1059
1060
1061 #----------------------------------------------------------------------
1062 sub method_string
1063 0 ▶{
Subroutine method_string: not called CC=9 SCAR=45.0
Pod undocumented
1064 0 my ($val) = @_ ;
1065 0 my $method_str = "" ;
1066
1067 0 ▶ if ($val == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($val == 0) { } 0 0 0
1068 {
1069 ## disabled
1070 0 $method_str = $METHOD_DISABLE ;
1071 }
1072 else
1073 {
1074 ## special
1075 0 foreach my $method_key (keys %{$Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method_special'}})
1076 {
1077 0 my $method_val = $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method_special'}{$method_key} ;
1078 0 ▶ if ($val == $method_val)
Branch: 1 branch
BranchTrueFalseTotal
if ($val == $method_val) 0 0 0
1079 {
1080 0 $method_str = $method_key ;
1081 0 last ;
1082 }
1083 }
1084 }
1085
1086 ## Not found it yet, so work out the string
1087 0 ▶ if (!$method_str)
Branch: 1 branch
BranchTrueFalseTotal
unless ($method_str) 0 0 0
1088 {
1089 0 foreach my $method_key (keys %{$Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method'}})
1090 {
1091 0 my $method_val = $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method'}{$method_key} ;
1092 0 ▶ if ($val & $method_val)
Branch: 1 branch
BranchTrueFalseTotal
if ($val & $method_val) 0 0 0
1093 {
1094 0 ▶ $method_str .= " + " if $method_str ;
Branch: 1 branch
BranchTrueFalseTotal
if $method_str 0 0 0
1095 0 $method_str .= $method_key ;
1096 }
1097 }
1098 }
1099
1100 0 ▶ if (!$method_str)
Branch: 1 branch
BranchTrueFalseTotal
unless ($method_str) 0 0 0
1101 {
1102 # error catchall
1103 0 $method_str = 'default' ;
1104 }
1105
1106 0 return $method_str ;
1107 }
1108
1109
1110 #----------------------------------------------------------------------
1111 sub parse_val
1112 84 ▶{
Subroutine parse_val: called CC=3 SCAR=11.2
Pod undocumented
1113 84 my ($val) = @_ ;
1114 84 my $ival ;
1115
1116 84 ▶ if ($val =~ /^0x([\da-z]+)/i)
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^0x([\da-z]+)/i) { } 0 84 84
elsif ($val =~ /([\d]+)/) { } 71 13 84
1117 {
1118 0 $ival = hex($1) ;
1119 }
1120 elsif ($val =~ /([\d]+)/)
1121 {
1122 71 $ival = int($1) ;
1123 }
1124
1125 84 return $ival ;
1126 }
1127
1128 #----------------------------------------------------------------------
1129 # Convert mode string into value (eg default - logo + audio)
1130 sub parse_method
1131 13 ▶{
Subroutine parse_method: called CC=25 SCAR=48.7
Pod undocumented
1132 13 my ($var, $val) = @_ ;
1133
1134 13 ▶print "parse_method($var, $val)\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 13 13
1135
1136 13 my $ival = parse_val($val) ;
1137 13 ▶ if (defined($ival))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ival) { } 0 13 13
1138 {
1139 ## Integer - if non-zero then ensure minimum settings are applied
1140 0 $val = $ival ;
1141
1142 0 ▶ if ($val)
Branch: 1 branch
BranchTrueFalseTotal
if ($val) 0 0 0
1143 {
1144 0 $val |= $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method_special'}{'MIN'} ;
1145 }
1146 }
1147 else
1148 {
1149 # Special string 'disable' or 'none' overrides everything
1150 13 ▶ if ($val =~ /$METHOD_DISABLE_REGEXP/)
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /$Linux::DVB::DVBT::Advert::Config::METHOD_DISABLE_REGEXP/) { } 12 1 13
1151 {
1152 # no detection
1153 12 $val = 0 ;
1154 }
1155 else
1156 {
1157 # Allow definitions of the form:
1158 # default -logo +audio = (black+logo+audio) - logo +audio = black+audio
1159 # logo + audio = logo+audio -> black+logo+audio (always add MIN)
1160 # -logo +audio = (black+logo+audio) - logo +audio = black+audio (infers default)
1161 #
1162 1 my $got_base=0 ;
1163 1 my $method=0 ;
1164 1 my $op = '' ;
1165 1 ▶ while ($val =~ /([\+\-]|\S+)/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /([\+\-]|\S+)/g) 1 1 2
1166 {
1167 1 my $token = $1 ;
1168 1 ▶ print " + token: \"$token\" (got base=$got_base) method=$method op=$op\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 1 1
1169 1 ▶ if ($token =~ /(\+|\-)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($token =~ /(\+|\-)/) { } 0 1 1
1170 {
1171 0 ▶ print " + + an op\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 0 0
1172 ## + or - operator, see if a base value has been specified, otherwise start with default
1173 0 $op = $1 ;
1174 0 ▶ if (!$got_base)
Branch: 1 branch
BranchTrueFalseTotal
unless ($got_base) 0 0 0
1175 {
1176 0 $method = $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method_special'}{'DEFAULT'} ;
1177 0 ++$got_base ;
1178 0 ▶ print " + + + set base method=$method\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 0 0
1179 }
1180 0 ▶ print " + + op=$op\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 0 0
1181 }
1182 else
1183 {
1184 1 my $method_key = uc $token ;
1185 1 ▶ print " + + a key $method_key\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 1 1
1186 1 ▶ if (exists($Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method'}{$method_key}))
Branch: 2 branches
BranchTrueFalseTotal
if (exists $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method'}{$method_key}) { } 0 1 1
elsif (exists $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method_special'}{$method_key}) { } 1 0 1
1187 {
1188 0 ▶ print " + + + exists! (op=$op)\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 0 0
1189 0 ▶ if (!$op)
Branch: 1 branch
BranchTrueFalseTotal
if (not $op) { } 0 0 0
1190 {
1191 # Set method to this value
1192 0 $method = $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method'}{$method_key} ;
1193 0 ++$got_base ;
1194 0 ▶ print " + + + set base method=$method\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 0 0
1195 }
1196 else
1197 {
1198 0 ▶ if ($op eq '+')
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq '+') { } 0 0 0
1199 {
1200 ## Add
1201 0 $method |= $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method'}{$method_key} ;
1202 }
1203 else
1204 {
1205 ## Subtract
1206 0 $method &= ~$Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method'}{$method_key} ;
1207 }
1208 0 $op = '' ;
1209 0 ▶ print " + + + set method=$method\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 0 0
1210 }
1211 }
1212 elsif (exists($Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method_special'}{$method_key}))
1213 {
1214 ## override with special value (e.g. 'default')
1215 1 $method = $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method_special'}{$method_key} ;
1216 1 $op = '' ;
1217 1 ▶ print " + + + set method=$method\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 1 1
1218 }
1219 }
1220 }
1221
1222 1 ▶ print " + method=$val\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 1 1
1223
1224 1 ▶ $method = 0 if $method < 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if $method < 0 0 1 1
1225 1 $method |= $Linux::DVB::DVBT::Advert::Constants::CONSTANTS{'Advert'}{'detection_method_special'}{'MIN'} ;
1226
1227 1 $val = $method ;
1228 1 ▶ print "METHOD: method=$val\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 1 1
1229 }
1230 }
1231 13 ▶print "METHOD: val=$val\n" if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 13 13
1232
1233 13 return $val ;
1234 }
1235
1236
1237 #----------------------------------------------------------------------
1238 sub parse_value
1239 84 ▶{
Subroutine parse_value: called CC=3 SCAR=11.0
Pod undocumented
1240 84 my ($var, $val) = @_ ;
1241
1242 84 ▶ if ($var eq $METHOD_VAR)
Branch: 1 branch
BranchTrueFalseTotal
if ($var eq $Linux::DVB::DVBT::Advert::Config::METHOD_VAR) { } 13 71 84
1243 {
1244 13 $val = parse_method($var, $val) ;
1245 }
1246 else
1247 {
1248 71 my $ival = parse_val($val) ;
1249 71 ▶ if (defined($ival))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ival) 71 0 71
1250 {
1251 71 $val = $ival ;
1252 }
1253 }
1254 84 return $val ;
1255 }
1256
1257 #----------------------------------------------------------------------
1258 sub parse_assignment
1259 452 ▶{
Subroutine parse_assignment: called CC=4 SCAR=13.9
Pod undocumented
1260 452 my ($line, $href) = @_ ;
1261
1262 452 ▶ if ($line =~ /(\S+)\s*=\s*(\S+.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /(\S+)\s*=\s*(\S+.*)/) 84 368 452
1263 {
1264 84 my ($var, $val) = ($1, $2) ;
1265 84 $val =~ s/\s+$// ;
1266 84 ▶ if ($var =~ /([\w\d]+)\.([\w\d]+)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /([\w\d]+)\.([\w\d]+)/) { } 43 41 84
1267 {
1268 # of the form:
1269 # logo.logo_threshold
1270 #
1271 # so save as:
1272 # {logo}{logo_threshold}
1273 #
1274 43 ▶ $href->{$1} ||= {} ;
Condition100%2/2
$href->{$1} ||= {}
l!l
367
MC/DC100%1/1
$href->{$1} ||= {}
$href->{$1}
Truth table100%2/2
A
A= $href->{$1}
Aresult
11
00
1275 43 $href->{$1}{$2} = parse_value($var, $val) ;
1276 }
1277 else
1278 {
1279 41 $href->{$var} = parse_value($var, $val) ;
1280 }
1281 }
1282 }
1283
1284 #----------------------------------------------------------------------
1285 # Need to copy globals down to key (if not already set), then use defaults
1286 # if neither set
1287 #
1288 sub cascade_settings
1289 0 ▶{
Subroutine cascade_settings: not called CC=9 SCAR=45.0
Pod undocumented
1290 0 my ($settings_href, $key, $defaults_href) = @_ ;
1291
1292 0 ▶ $settings_href ||= {} ;
Condition0%0/2
$settings_href ||= {}
l!l
00
MC/DC0%0/1
$settings_href ||= {}
$settings_href
Truth table0%0/2
A
A= $settings_href
Aresult
11
00
1293 0 ▶ $defaults_href ||= {} ;
Condition0%0/2
$defaults_href ||= {}
l!l
00
MC/DC0%0/1
$defaults_href ||= {}
$defaults_href
Truth table0%0/2
A
A= $defaults_href
Aresult
11
00
1294
1295 0 my $cascaded_href = {} ;
1296
1297 0 ▶print Data::Dumper->Dump(["cascade_settings($key) IN:", $settings_href, "DEFAULTS:", $defaults_href]) if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 0 0
1298
1299 ## start with defaults as a baseline
1300 0 ▶ if ($key && exists($defaults_href->{$key}))
Branch: 1 branch
BranchTrueFalseTotal
if ($key and exists $defaults_href->{$key}) { } 0 0 0
Condition0%0/3
$key and exists $defaults_href->{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
$key and exists $defaults_href->{$key}
$key exists $defaults_href->{$key}
Truth table0%0/3
A and B
A= $keyB= exists $defaults_href->{$key}
ABresult
0X0
100
111
1301 {
1302 0 _hash_copy_shallow($defaults_href->{$key}, $cascaded_href) ;
1303 }
1304 else
1305 {
1306 0 _hash_copy_shallow($defaults_href, $cascaded_href) ;
1307 }
1308
1309 ## copy over any settings defined in the global namespace
1310 0 _hash_copy_shallow($settings_href, $cascaded_href) ;
1311
1312 ## copy over any settings defined in the key's namespace
1313 0 ▶ if ($key && exists($settings_href->{$key}))
Branch: 1 branch
BranchTrueFalseTotal
if ($key and exists $settings_href->{$key}) { } 0 0 0
Condition0%0/3
$key and exists $settings_href->{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
$key and exists $settings_href->{$key}
$key exists $settings_href->{$key}
Truth table0%0/3
A and B
A= $keyB= exists $settings_href->{$key}
ABresult
0X0
100
111
1314 {
1315 0 _hash_copy_shallow($settings_href->{$key}, $cascaded_href) ;
1316 }
1317 else
1318 {
1319 0 _hash_copy_shallow($settings_href, $cascaded_href) ;
1320 }
1321 0 ▶print Data::Dumper->Dump(["cascade_settings($key) OUT:", $cascaded_href]) if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 0 0
1322
1323 0 return $cascaded_href ;
1324 }
1325
1326 #----------------------------------------------------------------------
1327 # Do a deep copy of one HASH heirarchy of settings onto another
1328 # List of settings starting with lowest priority
1329 #
1330 sub merge_settings
1331 6 ▶{
Subroutine merge_settings: called CC=4 SCAR=14.1
Pod undocumented
1332 6 my (@settings_list) = @_ ;
1333
1334 6 ▶print Data::Dumper->Dump(["merge_settings() IN:", \@settings_list]) if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 6 6
1335
1336 6 my $merged_href = {} ;
1337 6 foreach my $href (@settings_list)
1338 {
1339 13 _hash_copy_deep($href, $merged_href);
1340 }
1341
1342 6 ▶print Data::Dumper->Dump(["merge_settings() OUT:", $merged_href]) if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 6 6
1343
1344 6 return $merged_href ;
1345 }
1346
1347
1348
1349 #----------------------------------------------------------------------
1350 # Do a deep copy of the HASH and sub-hashes, propagating global settings down onto
1351 # any unset channel settings
1352 #
1353 sub channel_settings
1354 1 ▶{
Subroutine channel_settings: called CC=6 SCAR=20.5
Pod undocumented
1355 1 my ($advert_settings_href, $channel) = @_ ;
1356
1357 1 ▶ $channel ||= "" ;
Condition50%1/2
$channel ||= ""
l!l
10
MC/DC0%0/1
$channel ||= ""
$channel
Truth table50%1/2
A
A= $channel
Aresult
11
00
1358 1 $channel =~ s/^['"](.*)['"]$/$1/ ;
1359
1360 1 ▶print Data::Dumper->Dump(["channel_settings($channel) IN:", $advert_settings_href]) if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 1 1
1361
1362 1 my $cascaded_href = {} ;
1363
1364 ## Get copy of globals
1365 1 _hash_copy_deep($advert_settings_href->{$ADVERT_GLOBAL_SECTION}, $cascaded_href);
1366
1367 ## If channel specified, overwrite globals with channel-specific
1368 1 ▶ if ($channel && exists($advert_settings_href->{$channel}))
Branch: 1 branch
BranchTrueFalseTotal
if ($channel and exists $advert_settings_href->{$channel}) 0 1 1
Condition33%1/3
$channel and exists $advert_settings_href->{$channel}
!ll&&!rl&&r
010
MC/DC0%0/2
$channel and exists $advert_settings_href->{$channel}
$channel exists $advert_settings_href->{$channel}
Truth table33%1/3
A and B
A= $channelB= exists $advert_settings_href->{$channel}
ABresult
0X0
100
111
1369 {
1370 0 _hash_copy_deep($advert_settings_href->{$channel}, $cascaded_href);
1371
1372 ## Insert channel name into settings
1373 0 $cascaded_href->{'channel'} = $channel ;
1374 }
1375
1376 1 ▶print Data::Dumper->Dump(["channel_settings($channel) OUT:", $cascaded_href]) if $DEBUG >= 10 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG >= 10 0 1 1
1377 1 return $cascaded_href ;
1378 }
1379
1380
1381
1382 # ============================================================================================
1383 # ============================================================================================
1384
1385
1386 #---------------------------------------------------------------------------------
1387 # Copy key values from one hash into another. Follow a single depth of hierarchy for any
1388 # HASH entries
1389 sub _hash_copy_deep
1390 14 ▶{
Subroutine _hash_copy_deep: called CC=6 SCAR=18.0
1391 14 my ($base_href, $new_href) = @_ ;
1392
1393 14 ▶ $base_href ||= {} ;
Condition50%1/2
$base_href ||= {}
l!l
140
MC/DC0%0/1
$base_href ||= {}
$base_href
Truth table50%1/2
A
A= $base_href
Aresult
11
00
1394 14 ▶ croak "Error: cannot copy HASH because destination is not a HASH ref" if ref($new_href) ne 'HASH' ;
Branch: 1 branch
BranchTrueFalseTotal
if ref $new_href ne "HASH" 0 14 14
1395
1396 14 foreach my $key (keys %$base_href)
1397 {
1398 79 my $val = $base_href->{$key} ;
1399 79 ▶ if (ref($val) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'HASH') { } 39 40 79
1400 {
1401 # copy HASH entries
1402 39 ▶ $new_href->{$key} ||= {} ;
Condition100%2/2
$new_href->{$key} ||= {}
l!l
1128
MC/DC100%1/1
$new_href->{$key} ||= {}
$new_href->{$key}
Truth table100%2/2
A
A= $new_href->{$key}
Aresult
11
00
1403 $new_href->{$key} = {
1404 39 %{$new_href->{$key}},
1405 %$val
1406 };
1407 }
1408 else
1409 {
1410 # scalar
1411 40 $new_href->{$key} = $val ;
1412 }
1413 }
1414 }
1415
1416 #---------------------------------------------------------------------------------
1417 # Copy key values from one hash into another. Skips any HASH entries
1418 sub _hash_copy_shallow
1419 0 ▶{
Subroutine _hash_copy_shallow: not called CC=5 SCAR=34.0
1420 0 my ($base_href, $new_href) = @_ ;
1421
1422 0 ▶ $base_href ||= {} ;
Condition0%0/2
$base_href ||= {}
l!l
00
MC/DC0%0/1
$base_href ||= {}
$base_href
Truth table0%0/2
A
A= $base_href
Aresult
11
00
1423
1424 0 ▶ croak "Error: cannot copy HASH because destination is not a HASH ref" if ref($new_href) ne 'HASH' ;
Branch: 1 branch
BranchTrueFalseTotal
if ref $new_href ne "HASH" 0 0 0
1425
1426 0 foreach my $key (keys %$base_href)
1427 {
1428 0 my $val = $base_href->{$key} ;
1429 0 ▶ if (!ref($val))
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $val) 0 0 0
1430 {
1431 # scalar
1432 0 $new_href->{$key} = $val ;
1433 }
1434 }
1435 }
1436
1437 #---------------------------------------------------------------------------------
1438 # Convert template line into field/subvar
1439 sub _field_parse
1440 0 ▶{
Subroutine _field_parse: not called CC=2 SCAR=17.9
1441 0 my ($line) = @_ ;
1442 0 my ($field, $subvar) = ($line, '') ;
1443
1444 0 ▶ if ($field =~ /(\w+)\.(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /(\w+)\.(.*)/) 0 0 0
1445 {
1446 0 ($field, $subvar) = ($1, $2) ;
1447 }
1448 0 return ($field, $subvar) ;
1449 }
1450
1451 #---------------------------------------------------------------------------------
1452 # Lookup the comment text for this field/subvar
1453 sub _lookup_comment
1454 0 ▶{
Subroutine _lookup_comment: not called CC=5 SCAR=34.0
1455 0 my ($field, $subvar) = @_ ;
1456
1457 0 my $comment = '' ;
1458 0 my $name = $field ;
1459 0 ▶ $name .= ".$subvar" if $subvar ;
Branch: 1 branch
BranchTrueFalseTotal
if $subvar 0 0 0
1460
1461 0 ▶ if (exists($SETTINGS_COMMENTS{$name}))
Branch: 2 branches
BranchTrueFalseTotal
if (exists $SETTINGS_COMMENTS{$name}) { } 0 0 0
elsif ($subvar and exists $SETTINGS_COMMENTS{$subvar}) { } 0 0 0
1462 {
1463 ## use specific comment
1464 0 $comment = $SETTINGS_COMMENTS{$name} ;
1465 }
1466 ▶ elsif ($subvar && exists($SETTINGS_COMMENTS{$subvar}))
Condition0%0/3
$subvar and exists $SETTINGS_COMMENTS{$subvar}
!ll&&!rl&&r
000
MC/DC0%0/2
$subvar and exists $SETTINGS_COMMENTS{$subvar}
$subvar exists $SETTINGS_COMMENTS{$subvar}
Truth table0%0/3
A and B
A= $subvarB= exists $SETTINGS_COMMENTS{$subvar}
ABresult
0X0
100
111
1467 {
1468 ## no specific comment, so use global
1469 0 $comment = $SETTINGS_COMMENTS{$subvar} ;
1470 }
1471 0 return $comment ;
1472
1473 }
1474
1475
1476 # ============================================================================================
1477 # From Linux::DVB::DVBT::Config
1478 # ============================================================================================
1479
1480 #----------------------------------------------------------------------
1481
1482 =item B<read_dir($search_path, $fname)>
1483
1484 Find directories to read from - all readable directories in search path
1485
1486 =cut
1487
1488 sub read_dir
1489 5 ▶{
Subroutine read_dir: called CC=6 SCAR=17.9
Pod documented
1490 5 my ($search_path, $fname) = @_ ;
1491
1492 5 my @dirs = _expand_search_path($search_path) ;
1493 # my $dir ;
1494
1495 5 my @found = () ;
1496 5 foreach my $d (@dirs)
1497 {
1498 6 my $found=1 ;
1499 6 ▶ if (! -f "$d/$fname")
Branch: 1 branch
BranchTrueFalseTotal
unless (-f "$d/$fname") 1 5 6
1500 {
1501 ## can't find file, so mark as invalid directory
1502 1 $found=0 ;
1503 }
1504
1505 6 ▶ if ($found)
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 5 1 6
1506 {
1507 # $dir = $d ;
1508 # last ;
1509 5 push @found, $d ;
1510 }
1511 }
1512
1513 5 ▶ @found = ('.') unless @found ;
Branch: 1 branch
BranchTrueFalseTotal
unless @found 1 4 5
1514 5 ▶ print "Searched [ @$search_path ] : read dir=@found\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 5 0 5
1515
1516 # return $dir ;
1517 5 return @found ;
1518 }
1519
1520 #----------------------------------------------------------------------
1521
1522 =item B<write_dir($search_path, $fname)>
1523
1524 Find directory to write to - first writeable directory in search path
1525
1526 =cut
1527
1528 sub write_dir
1529 0 ▶{
Subroutine write_dir: not called CC=15 SCAR=54.8
Pod documented
1530 0 my ($search_path, $fname) = @_ ;
1531
1532 0 my @dirs = _expand_search_path($search_path) ;
1533 0 my $dir ;
1534
1535 0 ▶ print STDERR "Find dir to write to from $search_path ...\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
1536
1537 0 foreach my $d (@dirs)
1538 {
1539 0 my $found=1 ;
1540
1541 0 ▶ print STDERR " + processing $d\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
1542
1543 # See if dir exists
1544 0 ▶ if (!-d $d)
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $d) 0 0 0
1545 {
1546 # See if this user can create the dir
1547 0 eval {
1548 0 mkpath([$d], $DEBUG, 0755) ;
1549 };
1550 0 ▶ $found=0 if $@ ;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1551
1552 0 ▶ print STDERR " + $d does not exist - attempt to mkdir=$found\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
1553 }
1554
1555 0 ▶ if (-d $d)
Branch: 1 branch
BranchTrueFalseTotal
if (-d $d) 0 0 0
1556 {
1557 0 ▶ print STDERR " + $d does exist ...\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
1558
1559 # See if this user can write to the dir
1560 0 ▶ if (open my $fh, ">>$d/$fname")
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, ">>$d/$fname") { } 0 0 0
1561 {
1562 0 close $fh ;
1563 0 ▶ print STDERR " + + Write to $d/$fname succeded\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
1564 }
1565 else
1566 {
1567 0 ▶ print STDERR " + + Unable to write to $d/$fname - aborting this dir\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
1568
1569 0 $found = 0;
1570 }
1571 }
1572
1573 0 ▶ if ($found)
Branch: 1 branch
BranchTrueFalseTotal
if ($found) 0 0 0
1574 {
1575 0 $dir = $d ;
1576 0 last ;
1577 }
1578 }
1579
1580 0 ▶ print STDERR "Searched $search_path : write dir=".($dir?$dir:"")."\n" if $DEBUG ;
Branch: 2 branches
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
$dir ? : 0 0 0
1581
1582 0 return $dir ;
1583 }
1584
1585
1586 #----------------------------------------------------------------------
1587 # Split the search path & expand all the directories to absolute paths
1588 #
1589 sub _expand_search_path
1590 5 ▶{
Subroutine _expand_search_path: called CC=2 SCAR=7.0
1591 5 my ($search_path) = @_ ;
1592
1593 5 my @dirs = @$search_path ;
1594 5 foreach my $d (@dirs)
1595 {
1596 # Replace any '~' with $HOME
1597 6 $d =~ s/~/\$HOME/g ;
1598
1599 # Now replace any vars with values from the environment
1600 0 $d =~ s/\$(\w+)/$ENV{$1}/ge ;
1601
1602 # Ensure path is clean
1603 6 $d = File::Spec->rel2abs($d) ;
1604 }
1605
1606 5 return @dirs ;
1607 }
1608
1609
1610 #----------------------------------------------------------------------
1611 #
1612 sub _channel_search
1613 0 ▶{
Subroutine _channel_search: not called CC=13 SCAR=52.0
1614 0 my ($channel_name, $search_href) = @_ ;
1615
1616 0 my $found_channel_name ;
1617
1618 # start by just seeing if it's the correct name...
1619 0 ▶ if (exists($search_href->{$channel_name}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $search_href->{$channel_name}) { } 0 0 0
1620 {
1621 0 return $channel_name ;
1622 }
1623 else
1624 {
1625 ## Otherwise, try finding variations on the channel name
1626 0 my %search ;
1627
1628 0 $channel_name = lc $channel_name ;
1629
1630 # lower-case, no spaces
1631 0 my $srch = $channel_name ;
1632 0 $srch =~ s/\s+//g ;
1633 0 $search{$srch}=1 ;
1634
1635 # lower-case, replaced words with numbers, no spaces
1636 0 $srch = $channel_name ;
1637 0 foreach my $num (keys %NUMERALS)
1638 {
1639 0 $srch =~ s/\b($num)\b/$NUMERALS{$num}/ge ;
1640 }
1641 0 $srch =~ s/\s+//g ;
1642 0 $search{$srch}=1 ;
1643
1644 # lower-case, replaced numbers with words, no spaces
1645 0 $srch = $channel_name ;
1646 0 foreach my $num (keys %NUMERALS)
1647 {
1648 0 ▶print STDERR " -- $srch - replace $NUMERALS{$num} with $num..\n" if $DEBUG>3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG > 3 0 0 0
1649 0 $srch =~ s/($NUMERALS{$num})\b/$num/ge ;
1650 0 ▶print STDERR " -- -- $srch\n" if $DEBUG>3 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG > 3 0 0 0
1651 }
1652 0 $srch =~ s/\s+//g ;
1653 0 $search{$srch}=1 ;
1654
1655 0 ▶ print STDERR " + Searching tuning info [", keys %search, "]...\n" if $DEBUG>2 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG > 2 0 0 0
1656
1657 0 foreach my $chan (keys %$search_href)
1658 {
1659 0 my $srch_chan = lc $chan ;
1660 0 $srch_chan =~ s/\s+//g ;
1661
1662 0 foreach my $search (keys %search)
1663 {
1664 0 ▶ print STDERR " + + checking $search against $srch_chan \n" if $DEBUG>2 ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG > 2 0 0 0
1665 0 ▶ if ($srch_chan eq $search)
Branch: 1 branch
BranchTrueFalseTotal
if ($srch_chan eq $search) 0 0 0
1666 {
1667 0 $found_channel_name = $chan ;
1668 0 ▶ print STDERR " + found $channel_name\n" if $DEBUG ;
Branch: 1 branch
BranchTrueFalseTotal
if $Linux::DVB::DVBT::Advert::Config::DEBUG 0 0 0
1669 0 last ;
1670 }
1671 }
1672
1673 0 ▶ last if $found_channel_name ;
Branch: 1 branch
BranchTrueFalseTotal
if $found_channel_name 0 0 0
1674 }
1675 }
1676
1677 0 return $found_channel_name ;
1678 }
1679
1680 # ============================================================================================
1681 # END OF PACKAGE
1682
1683 =back
1684
1685 =cut
1686
1687 12 1;
1688
« blib/lib/Linux/DVB/DVBT/Advert.pm ↑ Summary blib/lib/Linux/DVB/DVBT/Advert/Mem.pm »