Update/CMakefile.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 94.4% 17 / 18 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 94.3% 67 / 71 CC 11 SCAR 21.2
CC
11
Cov
95%
update_cmakefile
11.0
BEGIN
1.0
BEGIN
1.0
CRAP 8.4
« Update/Bakefile0.pm ↑ Summary Update.pm »
1 package Makefile::Update::CMakefile;
2 # ABSTRACT: Update lists of files in CMake variables.
3  
4 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our @EXPORT = qw(update_cmakefile);
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.4'; # VERSION
11  
12  
13 # Variables in our input files use make-like $(var) syntax while CMake uses
14 # shell-like ${var}, so convert to the target format.
15 sub _var_to_cmake
16 7 ▶{
Subroutine _var_to_cmake: called CC=1 SCAR=0.0
17 7 my ($var) = @_;
18 7 $var =~ s/\((\w+)\)/{$1}/g;
19 7 $var;
20 }
21  
22  
23 sub update_cmakefile
24 1 ▶{
Subroutine update_cmakefile: called CC=11 SCAR=24.0
Pod documented
25 1 my ($in, $out, $vars) = @_;
26  
27 # Variable whose contents is being currently replaced.
28 1 my $var;
29  
30 # Hash with files defined for the specified variable as keys and 0 or 1
31 # depending on whether we have seen them in the input file as values.
32 my %files;
33  
34 # Set to 1 if we made any changes.
35 1 my $changed = 0;
36 1 ▶ while (<$in>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $in)) 14 1 15
37 # Preserve the original line to be able to output it with any comments
38 # that we strip below.
39 14 my $line_orig = $_;
40  
41 # Get rid of white space and comments.
42 14 chomp;
43 14 s/^\s+//;
44 14 s/\s+$//;
45 14 s/ *#.*$//;
46  
47 # Are we inside a variable definition?
48 14 ▶ if (defined $var) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $var) { } 9 5 14
elsif (/^set *\( *(\w+)$/ and exists $vars->{$1}) { } 2 6 8
49 9 ▶ if (/^\)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^\)$/) { } 2 7 9
elsif ($_) { } 6 1 7
50 # End of variable definition, check if we have any new files.
51 #
52 # TODO Insert them in alphabetical order.
53 2 ▶ while (my ($file, $seen) = each(%files)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %files) 7 2 9
54 7 ▶ if (!$seen) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen) 2 5 7
55 # This file wasn't present in the input, add it.
56 # TODO Use proper indentation.
57 2 print $out " $file\n";
58  
59 2 $changed = 1;
60 }
61 }
62  
63 2 undef $var;
64 } elsif ($_) {
65 # We're inside a variable definition.
66 6 ▶ if (not exists $files{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $files{$_}) 1 5 6
67 # This file was removed.
68 1 $changed = 1;
69 1 next;
70 }
71  
72 5 ▶ if ($files{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($files{$_}) { } 0 5 5
73 0 warn qq{Duplicate file "$_" in the definition of the } .
74 qq{variable "$var" at line $.\n}
75 } else {
76 5 $files{$_} = 1;
77 }
78 }
79 ▶ } elsif (/^set *\( *(\w+)$/ && exists $vars->{$1}) {
Condition66%2/3
/^set *\( *(\w+)$/ and exists $vars->{$1}
!ll&&!rl&&r
302
MC/DC50%1/2
/^set *\( *(\w+)$/ and exists $vars->{$1}
/^set *\( *(\w+)$/ exists $vars->{$1}
Truth table66%2/3
A and B
A= /^set *\( *(\w+)$/B= exists $vars->{$1}
ABresult
0X0
100
111
80 # Start of a new variable definition.
81 2 $var = $1;
82  
83 2 %files = map { _var_to_cmake($_) => 0 } @{$vars->{$var}};
84 }
85  
86 13 print $out $line_orig;
87 }
88  
89 $changed
90 1 }
91  
92 __END__
« Update/Bakefile0.pm ↑ Summary Update.pm »