Firemen/Common.pm

filter: Statementstmt 46.9% 130 / 277 Branchbran 28.6% 35 / 122 Conditioncond 22.2% 4 / 18 MC/DCmcdc 8.3% 1 / 12 Subroutinesub 84.3% 27 / 32 Podpod 100% 18 / 18 totaltotal 44.8% 215 / 479 CC 74 SCAR 42.5
CC
74
Cov
41%
getInstallationPath
184.7
dbConnect
132.0
printBlock
72.0
CRAP 69.9
« Firemen/Analyze.pm ↑ Summary Firemen/Load.pm »
1 #!/usr/bin/perl
2 ######################
3 #
4 # Copyright (C) 2011 - 2015 TU Clausthal, Institut fuer Maschinenwesen, Joachim Langenbach
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #
19 ######################
20  
21 # Pod::Weaver infos
22 # ABSTRACT: Shared functions used by other scripts from the Firemen module.
23  
24 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 package CAD::Firemen::Common;
28 {
29 16 $CAD::Firemen::Common::VERSION = '0.7.2';
30 }
31 16 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 16 our @EXPORT_OK = qw(
33 strip
34 print2ColsRightAligned
35 testPassed
36 testFailed
37 maxLength
38 printColored
39 printBlock
40 buildStatistic
41 getInstallationPath
42 getInstallationConfigCdb
43 getInstallationConfigPro
44 sharedDir
45 installationId
46 dbConnect
47 loadSettings
48 saveSettings
49 cleanSvn
50 );
51 16 our %EXPORT_TAGS = (
52 PRINTING => [qw(
53 print2ColsRightAligned
54 testPassed
55 testFailed
56 maxLength
57 printColored
58 printBlock
59 )]
60 );
61 16 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=9.2
62 16 ▶ if($^O eq "MSWin32"){
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 16 16
63 0 require Win32::Console::ANSI;
64 }
65 }
66 16 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 16 ▶use Term::ReadKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 16 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 16 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 16 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 16 ▶use YAML::XS qw(DumpFile LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
72 16 ▶use File::Path qw(rmtree);
Subroutine BEGIN: called CC=1 SCAR=0.0
73 16 ▶use File::Find::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
74 # Auto reset colors after print line
75 #$Term::ANSIColor::AUTORESET = 1;
76  
77 77208 ▶sub strip {
Subroutine strip: called CC=1 SCAR=0.0
Pod documented
78 77208 my $string = shift;
79 77208 chomp($string);
80 77208 $string =~ s/^\s+//;
81 77208 $string =~ s/\s+$//;
82 77208 $string =~ s/\s{2,}/ /g;
83 77208 return $string;
84 }
85  
86 243 ▶sub untaint {
Subroutine untaint: called CC=3 SCAR=11.0
Pod documented
87 243 my $string = shift;
88 243 ▶ if(!defined($string)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $string) 1 242 243
89 1 return "";
90 }
91 242 ▶ if($string =~ /^([\w\.\s\-\@\:\(\)\!\?\=\+\[\]\$\"\,\|\/\\;~]+)$/gs){
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ m<^([\w\.\s\-\@\:\(\)\!\?\=\+\[\]\$\"\,\|/\\;~]+)$>gs) 241 1 242
92 241 return $1;
93 }
94 1 return "";
95 }
96  
97 47 ▶sub print2ColsRightAligned {
Subroutine print2ColsRightAligned: called CC=2 SCAR=7.0
Pod documented
98 47 my $col1Text = untaint(shift);
99 47 my $col2Text = untaint(shift);
100 47 my $col2Color = untaint(shift);
101 47 my $terminalWidth = _terminalWidth();
102  
103 47 ▶ if(!defined($col2Color)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $col2Color) 0 47 47
104 0 $col2Color = "";
105 }
106  
107 47 my $len = $terminalWidth - length($col2Text) - 2;
108 47 print sprintf("%-". $len ."s", $col1Text);
109 47 printColored($col2Text, $col2Color);
110 47 print "\n";
111 }
112  
113 31 ▶sub testPassed {
Subroutine testPassed: called CC=1 SCAR=0.0
Pod documented
114 31 my $test = shift;
115 31 print2ColsRightAligned($test, "PASSED", "green");
116 }
117  
118 7 ▶sub testFailed {
Subroutine testFailed: called CC=1 SCAR=0.0
Pod documented
119 7 my $test = shift;
120 7 print2ColsRightAligned($test, "FAILED", "red");
121 }
122  
123 1 ▶sub maxLength {
Subroutine maxLength: called CC=3 SCAR=11.0
Pod documented
124 1 my @list = @_;
125  
126 1 my $max = 0;
127 1 foreach my $elem (@list){
128 4 ▶ if(length($elem) > $max){
Branch: 1 branch
BranchTrueFalseTotal
if (length $elem > $max) 1 3 4
129 1 $max = length($elem);
130 }
131 }
132 1 return $max;
133 }
134  
135 50 ▶sub printColored {
Subroutine printColored: called CC=4 SCAR=14.2
Pod documented
136 50 my $text = untaint(shift);
137 50 my $color = untaint(shift);
138  
139 50 ▶ if(!defined($text)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 50 50
140 0 return;
141 }
142 50 ▶ if(!defined($color) or ($color eq "")){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $color or $color eq "") 1 49 50
Condition66%2/3
not defined $color or $color eq ""
l!l&&r!l&&!r
0149
MC/DC50%1/2
not defined $color or $color eq ""
not defined $color $color eq ""
Truth table66%2/3
not(A) or B
A= not defined $colorB= $color eq ""
ABresult
1X1
011
000
143 1 $color = "RESET";
144 }
145  
146 50 print colored($text, $color);
147 50 print color 'reset';
148 }
149  
150 0 ▶ sub printBlock {
Subroutine printBlock: not called CC=8 SCAR=42.8
Pod documented
151 0 my $text = untaint(shift);
152 0 my $indent = untaint(shift);
153 0 my $color = untaint(shift);
154  
155 0 ▶ if(!defined($text)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 0 0
156 0 return;
157 }
158 0 ▶ if(!defined($indent)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $indent) 0 0 0
159 0 $indent = 0;
160 }
161 0 ▶ if(!defined($color) or ($color eq "")){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $color or $color eq "") 0 0 0
Condition0%0/3
not defined $color or $color eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $color or $color eq ""
not defined $color $color eq ""
Truth table0%0/3
not(A) or B
A= not defined $colorB= $color eq ""
ABresult
1X1
011
000
162 0 $color = "RESET";
163 }
164 # -2 is the linebreak
165 0 my $terminalWidth = _terminalWidth() - 2;
166 0 my $textWidth = $terminalWidth - $indent;
167  
168 # remove all linebreaks
169 0 $text =~ s/[\n\r]/ /gs;
170  
171 0 my $start = 0;
172 0 my $end = $textWidth;
173 0 ▶ while($start < length($text)){
Branch: 1 branch
BranchTrueFalseTotal
if ($start < length $text) 0 0 0
174 0 my $line = strip(substr($text, $start, $end));
175 0 my $max = $terminalWidth;
176 0 ▶ if($textWidth > length($line)){
Branch: 1 branch
BranchTrueFalseTotal
if ($textWidth > length $line) 0 0 0
177 0 $max = length($line) + $indent;
178 }
179 0 printColored(sprintf("%". $max ."s", $line), $color);
180 0 print "\n";
181 0 $start += $end;
182 # $end is the number of returned characters
183 0 ▶ if($start + $end > length($text)){
Branch: 1 branch
BranchTrueFalseTotal
if ($start + $end > length $text) 0 0 0
184 0 $end = length($text) - $start;
185 }
186 }
187 }
188  
189 0 ▶sub buildStatistic {
Subroutine buildStatistic: not called CC=7 SCAR=40.3
Pod documented
190 0 my $label = shift;
191 0 my $value = shift;
192 0 my $max = shift;
193 0 my $result = "";
194  
195 0 ▶ if(!defined($label)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $label) 0 0 0
196 0 return $result;
197 }
198 0 ▶ if(!defined($value)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 0 0
199 0 return $result;
200 }
201 0 ▶ if(!defined($max) || ($max == 0)){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $max or $max == 0) 0 0 0
Condition0%0/3
not defined $max or $max == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $max or $max == 0
not defined $max $max == 0
Truth table0%0/3
not(A) or B
A= not defined $maxB= $max == 0
ABresult
1X1
011
000
202 0 return $result;
203 }
204  
205 0 my $terminalWidth = _terminalWidth() - 2;
206 0 my $relValue = sprintf("%.0f", $value / $max * 100);
207 0 $label .= " [";
208 # - 6 is the percent itself (e.g.: " 69%, ")
209 0 my $valueLen = $terminalWidth - length($label) - 1 - 6 - length($value);
210 0 ▶ if($valueLen > 100){
Branch: 1 branch
BranchTrueFalseTotal
if ($valueLen > 100) 0 0 0
211 0 $valueLen = 100;
212 }
213 0 my $signs = floor($valueLen * $relValue / 100);
214 0 my $space = $valueLen - $signs;
215 0 $result = "[";
216 0 ▶ for(my $i = 0; $i < $signs; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $signs) 0 0 0
217 0 $result .= "=";
218 }
219 0 $result .= " ". sprintf("%". $space ."s %3s%%, %s", ("", $relValue, $value));
220 0 return $result;
221 }
222  
223 3 ▶sub getInstallationPath {
Subroutine getInstallationPath: called CC=25 SCAR=52.2
Pod documented
224 3 my $result = "";
225 3 my @tempPaths = ($ENV{'PATH'} =~ m/;([^;]+(?:proe|creo)[^;]+);/gi);
226 3 my @paths = ();
227 # add the paths from config
228 3 my $config = loadSettings();
229 3 ▶ if(defined($config)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config) 2 1 3
230 2 ▶ if(exists($config->{"paths"})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"paths"}) 2 0 2
231 2 foreach my $dir (@{$config->{"paths"}}){
232 2 push(@paths, $dir);
233 }
234 }
235 }
236  
237 # add path from ENV{PATH}, if not already done
238 3 ▶ for(my $i = 0; $i < scalar(@tempPaths); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @tempPaths) 3 3 6
239 3 ▶ if($tempPaths[$i] =~ m/([\W\w]+)(?:\\|\/)mech(?:\\|\/)bin/i){
Branch: 3 branches
BranchTrueFalseTotal
if ($tempPaths[$i] =~ m[([\W\w]+)(?:\\|/)mech(?:\\|/)bin]i) { } 0 3 3
elsif ($tempPaths[$i] =~ m[([\W\w]+)(?:\\|/)Parametric{0,1}(?:\\|/)bin$]i) { } 0 3 3
elsif ($tempPaths[$i] =~ m[([\W\w]+)(?:\\|/)bin$]i) { } 3 0 3
240 0 $tempPaths[$i] = $1;
241 }
242 elsif($tempPaths[$i] =~ m/([\W\w]+)(?:\\|\/)Parametric{0,1}(?:\\|\/)bin$/i){
243 0 $tempPaths[$i] = $1;
244  
245 0 my $alreadyInserted = 0;
246 0 foreach my $existing (@paths){
247 0 ▶ if(index($existing, $tempPaths[$i]) != -1){
Branch: 1 branch
BranchTrueFalseTotal
if (index($existing, $tempPaths[$i]) != -1) 0 0 0
248 0 $alreadyInserted = 1;
249 0 last;
250 }
251 }
252 0 ▶ if($alreadyInserted){
Branch: 1 branch
BranchTrueFalseTotal
if ($alreadyInserted) { } 0 0 0
253 0 $tempPaths[$i] = "";
254 }
255 else{
256 # only search for common files, if path is not already added!
257 0 print "Searching for Common Files directory of installation ". $tempPaths[$i] ."\n";
258 0 my @commonFilesDirectories = File::Find::Rule->name("Common Files")->in($tempPaths[$i]);
259 0 ▶ if(scalar(@commonFilesDirectories) == 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @commonFilesDirectories == 1) { } 0 0 0
260 0 testPassed(" Found Common Files for ". $tempPaths[$i]);
261 0 $tempPaths[$i] = $commonFilesDirectories[0];
262 }
263 else{
264 0 testFailed(" Found Common Files for ". $tempPaths[$i]);
265 }
266 }
267 }
268 elsif($tempPaths[$i] =~ m/([\W\w]+)(?:\\|\/)bin$/i){
269 3 $tempPaths[$i] = $1;
270 }
271 3 ▶ if($tempPaths[$i] ne ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($tempPaths[$i] ne "") 3 0 3
272 3 my $add = 1;
273 3 foreach my $existing (@paths){
274 2 ▶ if($existing eq $tempPaths[$i]){
Branch: 1 branch
BranchTrueFalseTotal
if ($existing eq $tempPaths[$i]) 2 0 2
275 2 $add = 0;
276 2 last;
277 }
278 }
279 3 ▶ if($add){
Branch: 1 branch
BranchTrueFalseTotal
if ($add) 1 2 3
280 1 push(@paths, $tempPaths[$i]);
281 }
282 }
283 }
284  
285 3 ▶ if(scalar(@paths) == 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @paths == 1) { } 3 0 3
286 3 $result = $paths[0];
287 }
288 else{
289 0 @paths = sort(@paths);
290 # determine default path
291 0 my $default = 0;
292 0 ▶ if(exists($config->{"defaultPath"})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"defaultPath"}) 0 0 0
293 0 ▶ for(my $i = 0; $i < scalar(@paths); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @paths) 0 0 0
294 0 ▶ if($config->{"defaultPath"} eq $paths[$i]){
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"defaultPath"} eq $paths[$i]) 0 0 0
295 0 $default = $i;
296 0 last;
297 }
298 }
299 }
300  
301 0 print "Possible installations:\n";
302 0 my $max = maxLength(@paths);
303 0 my $i = 0;
304 0 foreach my $dir (@paths){
305 0 print " ". sprintf("%-". $max ."s", $dir) ." ". $i ."\n";
306 0 $i++;
307 }
308 0 print "Or enter -1 to exit.\n";
309 0 print "Please choose one of the installations above [". $default ."]: ";
310 0 my $input = <>;
311 0 $input = strip($input);
312 0 ▶ if($input eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($input eq "") 0 0 0
313 0 $input = $default;
314 }
315 0 ▶ if($input =~ /^\d+$/){
Branch: 1 branch
BranchTrueFalseTotal
if ($input =~ /^\d+$/) 0 0 0
316 0 ▶ if(($input >= 0) && ($input < scalar(@paths))){
Branch: 1 branch
BranchTrueFalseTotal
if ($input >= 0 and $input < scalar @paths) { } 0 0 0
Condition0%0/3
$input >= 0 and $input < scalar @paths
!ll&&!rl&&r
000
MC/DC0%0/2
$input >= 0 and $input < scalar @paths
$input >= 0 $input < scalar @paths
Truth table0%0/3
A and B
A= $input >= 0B= $input < scalar @paths
ABresult
0X0
100
111
317 0 $result = $paths[$input];
318 }
319 else{
320 0 exit 0;
321 }
322 }
323 }
324  
325 # add all found paths to config
326 3 $config->{"paths"} = \@paths;
327 3 saveSettings($config);
328  
329 3 return $result;
330 }
331  
332 1 ▶sub getInstallationConfigCdb {
Subroutine getInstallationConfigCdb: called CC=4 SCAR=15.9
Pod documented
333 1 my $installPath = shift;
334 1 ▶ if(!defined($installPath) || ($installPath eq "")){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $installPath or $installPath eq "") 1 0 1
Condition33%1/3
not defined $installPath or $installPath eq ""
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $installPath or $installPath eq ""
not defined $installPath $installPath eq ""
Truth table33%1/3
not(A) or B
A= not defined $installPathB= $installPath eq ""
ABresult
1X1
011
000
335 1 $installPath = getInstallationPath();
336 }
337 1 ▶ if($installPath eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($installPath eq "") 0 1 1
338 0 return "";
339 }
340 1 return $installPath ."/text/config.cdb";
341 }
342  
343 1 ▶sub getInstallationConfigPro {
Subroutine getInstallationConfigPro: called CC=4 SCAR=15.9
Pod documented
344 1 my $installPath = shift;
345 1 ▶ if(!defined($installPath) || ($installPath eq "")){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $installPath or $installPath eq "") 1 0 1
Condition33%1/3
not defined $installPath or $installPath eq ""
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $installPath or $installPath eq ""
not defined $installPath $installPath eq ""
Truth table33%1/3
not(A) or B
A= not defined $installPathB= $installPath eq ""
ABresult
1X1
011
000
346 1 $installPath = getInstallationPath();
347 }
348 1 ▶ if($installPath eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($installPath eq "") 0 1 1
349 0 return "";
350 }
351 1 return $installPath ."/text/config.pro";
352 }
353  
354 7 ▶sub sharedDir {
Subroutine sharedDir: called CC=3 SCAR=11.3
Pod documented
355 7 my $dir = "c:/ProgramData/Firemen";
356 7 ▶ if(!-d $dir){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 1 6 7
357 1 ▶ if(!mkpath($dir)){
Branch: 1 branch
BranchTrueFalseTotal
unless (mkpath($dir)) 0 1 1
358 0 return "";
359 }
360 }
361 7 return $dir;
362 }
363  
364 0 ▶sub installationId {
Subroutine installationId: not called CC=3 SCAR=24.8
Pod documented
365 0 my $path = shift;
366 0 ▶ if(!defined($path)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 0 0 0
367 0 return "";
368 }
369 # get most upper folder (root folder) of creo or proe
370 0 ▶ if($path =~ m/^.+((?:creo|proe)[^(?:\\|\/)]+).{0,}(M[0-9]{1,})/i){
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[^.+((?:creo|proe)[^(?:\\|/)]+).{0,}(M[0-9]{1,})]i) { } 0 0 0
371 0 $path = $1 ."-". $2;
372 }
373 else{
374 0 return "";
375 }
376 0 $path =~ s/\s/-/g;
377 0 return $path;
378 }
379  
380 0 ▶sub dbConnect {
Subroutine dbConnect: not called CC=11 SCAR=48.8
Pod documented
381 0 my $installation = shift;
382 0 my $verbose = shift;
383 0 my $dbh = undef;
384 0 ▶ if(!defined($verbose)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $verbose) 0 0 0
385 0 $verbose = 0;
386 }
387 0 ▶ if(!defined($installation)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $installation) 0 0 0
388 0 return $dbh;
389 }
390  
391 0 $installation = installationId($installation);
392  
393 0 ▶ if($installation eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($installation eq "") 0 0 0
394 0 return $dbh;
395 }
396  
397 0 my $ref = loadSettings();
398 0 my $dbFile = "";
399 0 my %config = ();
400 0 my %dbs = ();
401 0 ▶ if(defined($ref)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref) 0 0 0
402 0 %config = %{$ref};
403 0 ▶ if(exists($config{"databases"})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config{"databases"}) 0 0 0
404 0 %dbs = %{$config{"databases"}};
405 0 ▶ if(exists($dbs{$installation})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dbs{$installation}) 0 0 0
406 0 $dbFile = $dbs{$installation};
407 }
408 }
409 }
410 0 ▶ if($dbFile eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($dbFile eq "") 0 0 0
411 0 $dbFile = "/options-". $installation .".sqlite";
412 0 $dbs{$installation} = $dbFile;
413 0 $config{"databases"} = \%dbs;
414 0 saveSettings(\%config);
415 }
416  
417 0 $dbFile = sharedDir() . $dbFile;
418 0 my $printError = 0;
419 0 ▶ if($verbose > 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
420 0 $printError = 1;
421 }
422 # we commit our self, to be much faster
423 0 $dbh = DBI->connect(
424 "dbi:SQLite:". $dbFile,
425 "",
426 "",
427 {PrintError => $printError, RaiseError => 0, AutoCommit => 0}
428 );
429 0 ▶ if(!$dbh){
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbh) 0 0 0
430 0 ▶ if($verbose > 0){
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 0) 0 0 0
431 0 print "Could not connect to database ". $dbFile ."\n";
432 }
433 0 return 0;
434 }
435 0 return $dbh;
436 }
437  
438 3 ▶sub loadSettings {
Subroutine loadSettings: called CC=2 SCAR=6.9
Pod documented
439 3 my $file = _settingsFile();
440 3 my $result;
441 3 ▶ if(!-e $file){
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 1 2 3
442 1 return $result;
443 }
444 2 return LoadFile($file);
445 }
446  
447 3 ▶sub saveSettings {
Subroutine saveSettings: called CC=2 SCAR=7.6
Pod documented
448 3 my $settingsRef = shift;
449 3 ▶ if(!defined($settingsRef)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $settingsRef) 0 3 3
450 0 return 0;
451 }
452 3 return DumpFile(_settingsFile(), $settingsRef);
453 }
454  
455 0 ▶sub cleanSvn {
Subroutine cleanSvn: not called CC=5 SCAR=34.0
Pod documented
456 0 my $dir = shift;
457 0 rmtree("$dir/.svn");
458 0 local *DIR;
459 0 ▶ opendir DIR, $dir or die "opendir $dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $dir or die "opendir ${dir}: $!" 0 0 0
460 0 for (readdir DIR) {
461 0 ▶ next if /^\.{1,2}$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\.{1,2}$/ 0 0 0
462 0 my $path = "$dir/$_";
463 0 ▶ cleanSvn($path) if -d $path;
Branch: 1 branch
BranchTrueFalseTotal
if -d $path 0 0 0
464 }
465 0 closedir DIR;
466 }
467  
468 7 ▶sub _settingsFile {
Subroutine _settingsFile: called CC=1 SCAR=0.0
469 7 return sharedDir() ."/config.yml";
470 }
471  
472 47 ▶sub _terminalWidth {
Subroutine _terminalWidth: called CC=2 SCAR=7.2
473 47 my $terminalWidth = 100;
474 47 eval{
475 47 my @tmp = GetTerminalSize();
476 47 ▶ if(defined($tmp[0])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp[0]) 0 47 47
477 0 $terminalWidth = $tmp[0];
478 }
479 };
480 47 return $terminalWidth;
481 }
482  
483 16 1;
484  
485 __END__
« Firemen/Analyze.pm ↑ Summary Firemen/Load.pm »