Firemen/Common.pm

filter: Statementstmt 14.0% 39 / 277 Branchbran 0.8% 1 / 122 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 37.5% 12 / 32 Podpod 100% 18 / 18 totaltotal 14.6% 70 / 479 CC 74 SCAR 52.1
CC
74
Cov
10%
getInstallationPath
650.0
dbConnect
132.0
printBlock
72.0
CRAP 183.6
« Firemen/ParseHelp/Wildfire5.pm ↑ Summary Firemen/Change.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 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 package CAD::Firemen::Common;
28 {
29 8 $CAD::Firemen::Common::VERSION = '0.7.1';
30 }
31 8 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 8 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 8 our %EXPORT_TAGS = (
52 PRINTING => [qw(
53 print2ColsRightAligned
54 testPassed
55 testFailed
56 maxLength
57 printColored
58 printBlock
59 )]
60 );
61 BEGIN {
62 8 ▶ if($^O eq "MSWin32"){
Subroutine BEGIN: called CC=2 SCAR=9.2
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "MSWin32") 0 8 8
63 0 require Win32::Console::ANSI;
64 }
65 }
66 8 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 8 ▶use Term::ReadKey;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 8 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 8 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 8 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 8 ▶use YAML::XS qw(DumpFile LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
72 8 ▶use File::Path qw(rmtree);
Subroutine BEGIN: called CC=1 SCAR=0.0
73 8 ▶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 sub strip {
78 0 ▶ my $string = shift;
Subroutine strip: not called CC=1 SCAR=6.9
Pod documented
79 0 chomp($string);
80 0 $string =~ s/^\s+//;
81 0 $string =~ s/\s+$//;
82 0 $string =~ s/\s{2,}/ /g;
83 0 return $string;
84 }
85  
86 sub untaint {
87 0 ▶ my $string = shift;
Subroutine untaint: not called CC=3 SCAR=24.8
Pod documented
88 0 ▶ if(!defined($string)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $string) 0 0 0
89 0 return "";
90 }
91 0 ▶ if($string =~ /^([\w\.\s\-\@\:\(\)\!\?\=\+\[\]\$\"\,\|\/\\;~]+)$/gs){
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ m<^([\w\.\s\-\@\:\(\)\!\?\=\+\[\]\$\"\,\|/\\;~]+)$>gs) 0 0 0
92 0 return $1;
93 }
94 0 return "";
95 }
96  
97 sub print2ColsRightAligned {
98 0 ▶ my $col1Text = untaint(shift);
Subroutine print2ColsRightAligned: not called CC=2 SCAR=17.9
Pod documented
99 0 my $col2Text = untaint(shift);
100 0 my $col2Color = untaint(shift);
101 0 my $terminalWidth = _terminalWidth();
102  
103 0 ▶ if(!defined($col2Color)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $col2Color) 0 0 0
104 0 $col2Color = "";
105 }
106  
107 0 my $len = $terminalWidth - length($col2Text) - 2;
108 0 print sprintf("%-". $len ."s", $col1Text);
109 0 printColored($col2Text, $col2Color);
110 0 print "\n";
111 }
112  
113 sub testPassed {
114 0 ▶ my $test = shift;
Subroutine testPassed: not called CC=1 SCAR=6.9
Pod documented
115 0 print2ColsRightAligned($test, "PASSED", "green");
116 }
117  
118 sub testFailed {
119 0 ▶ my $test = shift;
Subroutine testFailed: not called CC=1 SCAR=6.9
Pod documented
120 0 print2ColsRightAligned($test, "FAILED", "red");
121 }
122  
123 sub maxLength {
124 0 ▶ my @list = @_;
Subroutine maxLength: not called CC=3 SCAR=24.8
Pod documented
125  
126 0 my $max = 0;
127 0 foreach my $elem (@list){
128 0 ▶ if(length($elem) > $max){
Branch: 1 branch
BranchTrueFalseTotal
if (length $elem > $max) 0 0 0
129 0 $max = length($elem);
130 }
131 }
132 0 return $max;
133 }
134  
135 sub printColored {
136 0 ▶ my $text = untaint(shift);
Subroutine printColored: not called CC=4 SCAR=30.0
Pod documented
137 0 my $color = untaint(shift);
138  
139 0 ▶ if(!defined($text)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 0 0
140 0 return;
141 }
142 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
143 0 $color = "RESET";
144 }
145  
146 0 print colored($text, $color);
147 0 print color 'reset';
148 }
149  
150 sub printBlock {
151 0 ▶ my $text = untaint(shift);
Subroutine printBlock: not called CC=8 SCAR=42.8
Pod documented
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 sub buildStatistic {
190 0 ▶ my $label = shift;
Subroutine buildStatistic: not called CC=7 SCAR=40.3
Pod documented
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 sub getInstallationPath {
224 0 ▶ my $result = "";
Subroutine getInstallationPath: not called CC=25 SCAR=64.8
Pod documented
225 0 my @tempPaths = ($ENV{'PATH'} =~ m/;([^;]+(?:proe|creo)[^;]+);/gi);
226 0 my @paths = ();
227 # add the paths from config
228 0 my $config = loadSettings();
229 0 ▶ if(defined($config)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config) 0 0 0
230 0 ▶ if(exists($config->{"paths"})){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"paths"}) 0 0 0
231 0 foreach my $dir (@{$config->{"paths"}}){
232 0 push(@paths, $dir);
233 }
234 }
235 }
236  
237 # add path from ENV{PATH}, if not already done
238 0 ▶ for(my $i = 0; $i < scalar(@tempPaths); $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @tempPaths) 0 0 0
239 0 ▶ if($tempPaths[$i] =~ m/([\W\w]+)(?:\\|\/)mech(?:\\|\/)bin/i){
Branch: 3 branches
BranchTrueFalseTotal
if ($tempPaths[$i] =~ m[([\W\w]+)(?:\\|/)mech(?:\\|/)bin]i) { } 0 0 0
elsif ($tempPaths[$i] =~ m[([\W\w]+)(?:\\|/)Parametric{0,1}(?:\\|/)bin$]i) { } 0 0 0
elsif ($tempPaths[$i] =~ m[([\W\w]+)(?:\\|/)bin$]i) { } 0 0 0
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 0 $tempPaths[$i] = $1;
270 }
271 0 ▶ if($tempPaths[$i] ne ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($tempPaths[$i] ne "") 0 0 0
272 0 my $add = 1;
273 0 foreach my $existing (@paths){
274 0 ▶ if($existing eq $tempPaths[$i]){
Branch: 1 branch
BranchTrueFalseTotal
if ($existing eq $tempPaths[$i]) 0 0 0
275 0 $add = 0;
276 0 last;
277 }
278 }
279 0 ▶ if($add){
Branch: 1 branch
BranchTrueFalseTotal
if ($add) 0 0 0
280 0 push(@paths, $tempPaths[$i]);
281 }
282 }
283 }
284  
285 0 ▶ if(scalar(@paths) == 1){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @paths == 1) { } 0 0 0
286 0 $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 0 $config->{"paths"} = \@paths;
327 0 saveSettings($config);
328  
329 0 return $result;
330 }
331  
332 sub getInstallationConfigCdb {
333 0 ▶ my $installPath = shift;
Subroutine getInstallationConfigCdb: not called CC=4 SCAR=30.0
Pod documented
334 0 ▶ if(!defined($installPath) || ($installPath eq "")){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $installPath or $installPath eq "") 0 0 0
Condition0%0/3
not defined $installPath or $installPath eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $installPath or $installPath eq ""
not defined $installPath $installPath eq ""
Truth table0%0/3
not(A) or B
A= not defined $installPathB= $installPath eq ""
ABresult
1X1
011
000
335 0 $installPath = getInstallationPath();
336 }
337 0 ▶ if($installPath eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($installPath eq "") 0 0 0
338 0 return "";
339 }
340 0 return $installPath ."/text/config.cdb";
341 }
342  
343 sub getInstallationConfigPro {
344 0 ▶ my $installPath = shift;
Subroutine getInstallationConfigPro: not called CC=4 SCAR=30.0
Pod documented
345 0 ▶ if(!defined($installPath) || ($installPath eq "")){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $installPath or $installPath eq "") 0 0 0
Condition0%0/3
not defined $installPath or $installPath eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $installPath or $installPath eq ""
not defined $installPath $installPath eq ""
Truth table0%0/3
not(A) or B
A= not defined $installPathB= $installPath eq ""
ABresult
1X1
011
000
346 0 $installPath = getInstallationPath();
347 }
348 0 ▶ if($installPath eq ""){
Branch: 1 branch
BranchTrueFalseTotal
if ($installPath eq "") 0 0 0
349 0 return "";
350 }
351 0 return $installPath ."/text/config.pro";
352 }
353  
354 sub sharedDir {
355 0 ▶ my $dir = "c:/ProgramData/Firemen";
Subroutine sharedDir: not called CC=3 SCAR=24.8
Pod documented
356 0 ▶ if(!-d $dir){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
357 0 ▶ if(!mkpath($dir)){
Branch: 1 branch
BranchTrueFalseTotal
unless (mkpath($dir)) 0 0 0
358 0 return "";
359 }
360 }
361 0 return $dir;
362 }
363  
364 sub installationId {
365 0 ▶ my $path = shift;
Subroutine installationId: not called CC=3 SCAR=24.8
Pod documented
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 sub dbConnect {
381 0 ▶ my $installation = shift;
Subroutine dbConnect: not called CC=11 SCAR=48.8
Pod documented
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 sub loadSettings {
439 0 ▶ my $file = _settingsFile();
Subroutine loadSettings: not called CC=2 SCAR=17.9
Pod documented
440 0 my $result;
441 0 ▶ if(!-e $file){
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
442 0 return $result;
443 }
444 0 return LoadFile($file);
445 }
446  
447 sub saveSettings {
448 0 ▶ my $settingsRef = shift;
Subroutine saveSettings: not called CC=2 SCAR=17.9
Pod documented
449 0 ▶ if(!defined($settingsRef)){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $settingsRef) 0 0 0
450 0 return 0;
451 }
452 0 return DumpFile(_settingsFile(), $settingsRef);
453 }
454  
455 sub cleanSvn {
456 0 ▶ my $dir = shift;
Subroutine cleanSvn: not called CC=5 SCAR=34.0
Pod documented
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 sub _settingsFile {
469 0 ▶ return sharedDir() ."/config.yml";
Subroutine _settingsFile: not called CC=1 SCAR=6.9
470 }
471  
472 sub _terminalWidth {
473 0 ▶ my $terminalWidth = 100;
Subroutine _terminalWidth: not called CC=2 SCAR=17.9
474 0 eval{
475 0 my @tmp = GetTerminalSize();
476 0 ▶ if(defined($tmp[0])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tmp[0]) 0 0 0
477 0 $terminalWidth = $tmp[0];
478 }
479 };
480 0 return $terminalWidth;
481 }
482  
483 8 1;
484  
485 __END__
« Firemen/ParseHelp/Wildfire5.pm ↑ Summary Firemen/Change.pm »