lib/MakeWithPerl.pm

filter: Statementstmt 19.0% 33 / 173 Branchbran 3.2% 3 / 92 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 6 totaltotal 13.6% 42 / 308 SCAR 77.4
CC
58
Cov
13%
makeWithPerl
1857.4
test
17.1
removeClasses
6.0
CRAP 2301.5
↑ Summary blib/lib/MakeWithPerl.pm »
1 #!/usr/bin/perl -I/home/phil/perl/cpan/DataTableText/lib -I/home/phil/perl/cpan/JavaDoc/lib -I/home/phil/perl/cpan/DitaPCD/lib/ -I/home/phil/perl/cpan/DataEditXml/lib/ -I/home/phil/perl/cpan/GitHubCrud/lib/ -I/home/phil/perl/cpan/DataDFA/lib/ -I/home/phil/perl/cpan/DataNFA/lib/ -I//home/phil/perl/cpan/PreprocessOps/lib/
2 #-------------------------------------------------------------------------------
3 # Make with Perl
4 # Philip R Brenan at gmail dot com, Appa Apps Ltd, 2017
5 #-------------------------------------------------------------------------------
6 package MakeWithPerl;
7 our $VERSION = "20210533";
8 use warnings FATAL => qw(all);
9 use strict;
10 use Carp qw(confess);
11 use Data::Dump qw(dump);
12 use Data::Table::Text qw(:all);
13 use Getopt::Long;
14 use utf8;
15  
16 1 ▶sub mwpl {qq(makeWithPerlLocally.pl)} # Make with Perl locally
Subroutine mwpl: called CC=1 SCAR=0.0
Pod undocumented
17  
18 my $javaHome; # Location of java files
19 my $cIncludes; # C includes folder
20 my $compile; # Compile
21 my $coverage; # Get coverage of code
22 my $doc; # Documentation
23 my $gccVersion; # Alternate version of gcc is set. Example: --gccVersion gcc-10
24 my $htmlToPdf; # Convert html to pdf
25 my $run; # Run
26 my $upload; # Upload files
27 my $valgrind; # Check C memory usage
28 my $xmlCatalog; # Verify xml
29  
30 sub makeWithPerl { # Make a file
31 1 ▶GetOptions(
Subroutine makeWithPerl: called CC=52 SCAR=75.3
Pod undocumented
32 'cIncludes=s' =>\$cIncludes,
33 'compile' =>\$compile,
34 'coverage' =>\$coverage,
35 'doc' =>\$doc,
36 'gccVersion=s'=>\$gccVersion,
37 'htmlToPdf' =>\$htmlToPdf,
38 'run' =>\$run,
39 'valgrind' =>\$valgrind,
40 'upload' =>\$upload,
41 'xmlCatalog=s'=>\$xmlCatalog,
42 );
43  
44 1 ▶unless($compile or $run or $doc or $upload) # Check action
Branch: 1 branch
BranchTrueFalseTotal
unless ($compile or $run or $doc or $upload) 0 0 0
Condition0%0/9
$compile or $run or $doc or $upload
l!l&&r!l&&!r
000
$compile or $run or $doc
l!l&&r!l&&!r
000
$compile or $run
l!l&&r!l&&!r
000
MC/DC0%0/4
$compile or $run or $doc or $upload
$compile $run $doc $upload
Truth table0%0/5
A or B or C or D
A= $compileB= $runC= $docD= $upload
ABCDresult
1XXX1
01XX1
001X1
00011
00000
45 1 {confess "Specify --compile or --run or --doc or --upload";
46 }
47  
48 1 ▶my $file = shift @ARGV // $0; # File to process
Condition0%0/3
shift @ARGV // $0
l!l&&r!l&&!r
000
MC/DC0%0/2
shift @ARGV // $0
shift @ARGV $0
Truth table0%0/3
A // B
A= shift @ARGVB= $0
ABresult
1X1
011
000
49  
50 1 ▶unless($file) # Confirm we have a file
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 0 0 0
51 1 {confess "Use %f to specify the file to process";
52 }
53  
54 1 ▶if (! -e $file) # No such file
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
55 1 {confess "No such file:\n$file"
56 }
57  
58 1 ▶if ($upload) # Upload files to GitHub
Branch: 1 branch
BranchTrueFalseTotal
if ($upload) 0 0 0
59 1 {my @d = split m{/}, $file; # Split file name
60 1 pop @d;
61 1 ▶ while(@d) # Look for a folder that contains a push command
Branch: 1 branch
BranchTrueFalseTotal
if (@d) 0 0 0
62 1 {my $u = "/".fpe(@d, qw(pushToGitHub pl));
63 1 ▶ if (-e $u)
Branch: 1 branch
BranchTrueFalseTotal
if (-e $u) 0 0 0
64 1 {say STDERR $u;
65 1 qx(perl $u);
66 1 exit;
67 }
68 1 pop @d;
69 }
70 1 confess "Unable to find pushToGitHub in folders down to $file";
71 }
72  
73 1 ▶if ($doc) # Documentation
Branch: 1 branch
BranchTrueFalseTotal
if ($doc) 0 0 0
74 1 ▶ {if ($file =~ m((pl|pm)\Z)s) # Document perl
Branch: 2 branches
BranchTrueFalseTotal
if ($file =~ /(pl|pm)\Z/s) { } 0 0 0
elsif ($file =~ /(java)\Z/s) { } 0 0 0
75 1 {say STDERR "Document perl $file";
76 1 updatePerlModuleDocumentation($file);
77 }
78 elsif ($file =~ m((java)\Z)s) # Document java
79 1 {say STDERR "Document java $file";
80  
81 1 my %files;
82 1 for(findFiles($javaHome))
83 1 ▶ {next if m/Test\.java\Z/ or m(/java/z/); # Exclude test files and /java/ sub folders
Branch: 1 branch
BranchTrueFalseTotal
if /Test\.java\Z/ or m[/java/z/] 0 0 0
Condition0%0/3
/Test\.java\Z/ or m[/java/z/]
l!l&&r!l&&!r
000
MC/DC0%0/2
/Test\.java\Z/ or m[/java/z/]
/Test\.java\Z/ m[/java/z/]
Truth table0%0/3
A or B
A= /Test\.java\Z/B= m[/java/z/]
ABresult
1X1
011
000
84 1 ▶ $files{$_}++ if /\.java\Z/
Branch: 1 branch
BranchTrueFalseTotal
if /\.java\Z/ 0 0 0
85 }
86 1 confess;
87 #my $j = Java::Doc::new;
88 #$j->source = [sort keys %files];
89 #$j->target = my $f = filePathExt($javaHome, qw(documentation html));
90 #$j->indent = 20;
91 #$j->colors = [map {"#$_"} qw(ccFFFF FFccFF FFFFcc CCccFF FFCCcc ccFFCC)];
92 #$j->html;
93 #qx(opera $f);
94 }
95 else
96 1 {confess "Unable to document file $file";
97 }
98 exit
99 1 }
100  
101 1 ▶if (-e mwpl and $run) # Make with Perl locally
Branch: 1 branch
BranchTrueFalseTotal
if (-e mwpl() and $run) 0 0 0
Condition0%0/3
-e mwpl() and $run
!ll&&!rl&&r
000
MC/DC0%0/2
-e mwpl() and $run
-e mwpl() $run
Truth table0%0/3
A and B
A= -e mwpl()B= $run
ABresult
0X0
100
111
102 0 {my $p = join ' ', @ARGV;
103 0 my $c = mwpl;
104 0 print STDERR qx(perl -CSDA $c $p);
105 0 exit;
106 }
107  
108 0 ▶if ($file =~ m(\.p[lm]\Z)) # Perl
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.p[lm]\Z/) 0 0 0
109 0 ▶ {if ($compile) # Syntax check perl
Branch: 3 branches
BranchTrueFalseTotal
if ($compile) { } 0 0 0
elsif ($run) { } 0 0 0
elsif ($doc) { } 0 0 0
110 0 {print STDERR qx(perl -CSDA -cw "$file");
111 }
112 elsif ($run) # Run perl
113 0 ▶ {if ($file =~ m(.cgi\Z)s) # Run from web server
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /.cgi\Z/s) { } 0 0 0
114 0 {&cgiPerl($file);
115 }
116 else # Run from command line
117 0 {say STDERR qq(perl -CSDA -w "$file");
118 0 print STDERR qx(perl -CSDA -w "$file");
119 }
120 }
121 elsif ($doc) # Document perl
122 0 {say STDERR "Document perl $file";
123 0 updatePerlModuleDocumentation($file);
124 }
125 0 exit;
126 }
127  
128 0 ▶if ($file =~ m(\.(dita|ditamap|xml)\Z)) # Process xml
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.(dita|ditamap|xml)\Z/) 0 0 0
129 0 {my $source = readFile($file);
130 0 my $C = $xmlCatalog;
131 0 my $c = qq(xmllint --noent --noout "$file" && echo "Parses OK!" && export XML_CATALOG_FILES=$C && xmllint --noent --noout --valid - < "$file" && echo Valid);
132 0 say STDERR $c;
133 0 say STDERR qx($c);
134 0 exit;
135 }
136  
137 0 ▶if ($file =~ m(\.asm\Z)) # Process assembler
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.asm\Z/) 0 0 0
138 0 {my $o = setFileExtension $file, q(o);
139 0 my $e = setFileExtension $file;
140 0 my $l = setFileExtension $file, q(txt);
141 0 my $c = qq(nasm -f elf64 -g -l $l -o $o $file);
142 0 ▶ if ($compile)
Branch: 1 branch
BranchTrueFalseTotal
if ($compile) { } 0 0 0
143 0 {say STDERR $c;
144 0 say STDERR qx($c; cat $l);
145 }
146 else
147 0 {$c = "$c; ld -o $e $o; $e";
148 0 say STDERR $c;
149 0 say STDERR qx($c);
150 }
151 0 exit;
152 }
153  
154 0 ▶if ($file =~ m(\.cp*\Z)) # GCC
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.cp*\Z/) 0 0 0
155 0 {my $cp = join ' ', map {split /\s+/} grep {!/\A#/} split /\n/, <<END; # Compiler options
156 -finput-charset=UTF-8 -fmax-errors=7 -rdynamic
157 -Wall -Wextra -Wno-unused-function
158 END
159  
160 0 ▶ my $gcc = $gccVersion // 'gcc'; # Gcc version 10
Condition0%0/2
$gccVersion // "gcc"
l!l
00
MC/DC0%0/1
$gccVersion // "gcc"
$gccVersion
Truth table0%0/2
A
A= $gccVersion
Aresult
11
00
161 0 ▶ if ($compile)
Branch: 1 branch
BranchTrueFalseTotal
if ($compile) { } 0 0 0
162 0 {my $cmd = qq($gcc $cp -c "$file" -o /dev/null); # Syntax check
163 0 say STDERR $cmd;
164 0 print STDERR $_ for qx($cmd);
165 }
166 else
167 0 {my $e = $file =~ s(\.cp?p?\Z) ()gsr; # Execute
168 0 my $o = fpe($e, q(o)); # Object file
169 0 unlink $e, $o;
170  
171 0 my $c = qq($gcc $cp -o "$e" "$file" && $e); # Compile and run
172 0 lll qq($c);
173 0 lll qx($c);
174 0 unlink $o;
175  
176 0 ▶ if ($valgrind) # Valgrind requested
Branch: 1 branch
BranchTrueFalseTotal
if ($valgrind) 0 0 0
177 0 {my $c = qq(valgrind --leak-check=full --leak-resolution=high --show-leak-kinds=definite --track-origins=yes $e 2>&1);
178 0 lll qq($c);
179 0 my $result = qx($c);
180 0 lll $result;
181 0 ▶ exit(1) unless $result =~ m(ERROR SUMMARY: 0 errors from 0 contexts);
Branch: 1 branch
BranchTrueFalseTotal
unless $result =~ /ERROR SUMMARY: 0 errors from 0 contexts/ 0 0 0
182 0 lll "SUCCESS: no memory leaks"
183 }
184 }
185 0 exit;
186 }
187  
188 0 ▶if ($file =~ m(\.js\Z)) # Javascript
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.js\Z/) 0 0 0
189 0 ▶ {if ($compile)
Branch: 1 branch
BranchTrueFalseTotal
if ($compile) { } 0 0 0
190 0 {say STDERR "Compile javascript $file";
191 0 print STDERR qx(nodejs -c "$file"); # Syntax check javascript
192 }
193 else
194 0 {my $c = qq(nodejs --max_old_space_size=4096 "$file"); # Run javascript
195 0 say STDERR $c;
196 0 print STDERR qx($c);
197 0 say STDERR q();
198 }
199 0 exit;
200 }
201  
202 0 ▶if ($file =~ m(\.sh\Z)) # Bash script
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.sh\Z/) 0 0 0
203 0 ▶ {if ($compile)
Branch: 1 branch
BranchTrueFalseTotal
if ($compile) { } 0 0 0
204 0 {say STDERR "Test bash $file";
205 0 print STDERR qx(bash -x "$file"); # Debug bash
206 }
207 else
208 0 {print STDERR qx(bash "$file"); # Bash
209 }
210 0 exit;
211 }
212  
213 0 ▶if ($file =~ m(\.adblog\Z)) # Android log
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.adblog\Z/) 0 0 0
214 0 {my $adb = q(/home/phil/android/sdk/platform-tools/adb);
215 0 my $c = qq($adb -e logcat "*:W" -d > $file && $adb -e logcat -c);
216 0 say STDERR "Android log\n$c";
217 0 print STDERR qx($c);
218 0 exit;
219 }
220  
221 0 ▶if ($file =~ m(\.java\Z)) # Java
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.java\Z/) 0 0 0
222 0 {my ($name, undef, $ext) = fileparse($file, qw(.java)); # Parse file name
223 0 my $package = &getPackageNameFromFile($file); # Get package name
224 0 my $cp = fpd($javaHome, qw(Classes)); # Folder containing java classes
225 0 ▶ if ($compile) # Compile
Branch: 1 branch
BranchTrueFalseTotal
if ($compile) { } 0 0 0
226 0 {my $c = "javac -g -d $cp -cp $cp -Xlint -Xdiags:verbose $file -Xmaxerrs 99";# Syntax check Java
227 0 say STDERR $c;
228 0 print STDERR qx($c);
229 }
230 else # Compile and run
231 0 ▶ {my $class = $package ? "$package.$name" : $name; # Class location
Branch: 1 branch
BranchTrueFalseTotal
$package ? : 0 0 0
232 0 my $p = join ' ', @ARGV; # Collect the remaining parameters and pass them to the java application
233 0 my $c = "javac -g -d $cp -cp $cp $file && java -ea -cp $cp $class $p"; # Run java
234 0 say STDERR $c;
235 0 print STDERR qx($c);
236 }
237 0 &removeClasses;
238 0 exit;
239 }
240  
241 0 ▶if ($file =~ m(\.(txt|htm)\Z)) # Html
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.(txt|htm)\Z/) 0 0 0
242 0 {my $s = expandWellKnownUrlsInHtmlFormat
243 expandWellKnownWordsAsUrlsInHtmlFormat
244 readFile $file;
245 0 my $o = setFileExtension $file, q(html); # Output file
246 0 my $f = owf $o, $s;
247  
248 0 ▶ if ($htmlToPdf) # Convert html to pdf if requested
Branch: 1 branch
BranchTrueFalseTotal
if ($htmlToPdf) { } 0 0 0
249 0 {my $p = setFileExtension($file, q(pdf));
250 0 say STDERR qx(wkhtmltopdf $f $p);
251 }
252 else # Show html in opera
253 0 {my $c = qq(timeout 3m opera $o);
254 0 say STDERR qq($c);
255 0 say STDERR qx($c);
256 }
257 }
258  
259 0 ▶if ($file =~ m(\.py\Z)) # Python
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.py\Z/) 0 0 0
260 0 ▶ {if ($compile) # Syntax check
Branch: 3 branches
BranchTrueFalseTotal
if ($compile) { } 0 0 0
elsif ($run) { } 0 0 0
elsif ($doc) { } 0 0 0
261 0 {print STDERR qx(python3 -m py_compile "$file");
262 }
263 elsif ($run) # Run
264 0 {print STDERR qx(python3 "$file");
265 }
266 elsif ($doc) # Document
267 0 {say STDERR "Document perl $file";
268 0 updatePerlModuleDocumentation($file);
269 }
270 0 exit;
271 }
272  
273 0 ▶if ($file =~ m(\.(vala)\Z)) # Vala
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.(vala)\Z/) 0 0 0
274 0 {my $lib = "--pkg gtk+-3.0"; # Libraries
275 0 ▶ if ($compile) # Syntax check
Branch: 3 branches
BranchTrueFalseTotal
if ($compile) { } 0 0 0
elsif ($run) { } 0 0 0
elsif ($doc) { } 0 0 0
276 0 {print STDERR qx(valac -c "$file" $lib);
277 }
278 elsif ($run) # Run
279 0 {print STDERR qx(vala "$file" $lib);
280 }
281 elsif ($doc) # Document
282 0 {say STDERR "Document perl $file";
283 0 updatePerlModuleDocumentation($file);
284 }
285 0 exit;
286 }
287  
288 sub removeClasses
289 0 ▶ {unlink for fileList("*.class")
Subroutine removeClasses: called CC=2 SCAR=17.9
Pod undocumented
290 }
291  
292 sub getPackageNameFromFile($) # Get package name from java file
293 0 ▶ {my ($file) = @_; # File to read
Subroutine getPackageNameFromFile: called CC=1 SCAR=6.9
Pod undocumented
294 0 my $s = readFile($file);
295 0 my ($p) = $s =~ m/package\s+(\S+)\s*;/;
296 0 $p
297 }
298  
299 sub cgiPerl($) # Run perl on web server
300 0 ▶ {my ($file) = @_; # File to read
Subroutine cgiPerl: called CC=2 SCAR=17.9
Pod undocumented
301  
302 0 my $r = qx(perl -CSDA -cw "$file" 2>&1);
303 0 ▶ if ($r !~ m(syntax OK))
Branch: 1 branch
BranchTrueFalseTotal
if (not $r =~ /syntax OK/) { } 0 0 0
304 0 {say STDERR $r;
305 }
306 else
307 0 {my $base = fne $file;
308 0 my $target = fpf(q(/usr/lib/cgi-bin), $base);
309 0 lll qx(echo 121212 | sudo -S cp $file $target);
310 0 lll qx(echo 121212 | sudo chmod ugo+rx $target);
311 0 lll qx(opera http://localhost/cgi-bin/$base &);
312 }
313 }
314 }
315  
316 #d
317 #-------------------------------------------------------------------------------
318 # Export - eeee
319 #-------------------------------------------------------------------------------
320  
321 use Exporter qw(import);
322  
323 use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
324  
325 @ISA = qw(Exporter);
326 @EXPORT = qw();
327 @EXPORT_OK = qw(
328 );
329 %EXPORT_TAGS = (all=>[@EXPORT, @EXPORT_OK]);
330  
331 # podDocumentation
332 =pod
333  
334 =encoding utf-8
335  
336 =head1 Name
337  
338 MakeWithPerl - Make with Perl
339  
340 =head1 Synopsis
341  
342 Integrated development environment for Geany or similar editor for compiling
343 running and documenting programs written in a number of languages.
344  
345 =head2 Installation:
346  
347 sudo cpan install MakeWithPerl
348  
349 =head2 Operation
350  
351 Configure Geany as described at
352 L<README.md|https://github.com/philiprbrenan/MakeWithPerl>.
353  
354 =head1 Description
355  
356 Make with Perl
357  
358  
359 Version "20210533".
360  
361  
362 The following sections describe the methods in each functional area of this
363 module. For an alphabetic listing of all methods by name see L<Index|/Index>.
364  
365  
366  
367  
368 =head1 Index
369  
370  
371 =head1 Installation
372  
373 This module is written in 100% Pure Perl and, thus, it is easy to read,
374 comprehend, use, modify and install via B<cpan>:
375  
376 sudo cpan install MakeWithPerl
377  
378 =head1 Author
379  
380 L<philiprbrenan@gmail.com|mailto:philiprbrenan@gmail.com>
381  
382 L<http://www.appaapps.com|http://www.appaapps.com>
383  
384 =head1 Copyright
385  
386 Copyright (c) 2016-2021 Philip R Brenan.
387  
388 This module is free software. It may be used, redistributed and/or modified
389 under the same terms as Perl itself.
390  
391 =cut
392  
393  
394  
395 # Tests and documentation
396  
397 sub test
398 0 ▶ {my $p = __PACKAGE__;
Subroutine test: called CC=5 SCAR=28.4
Pod undocumented
399 0 binmode($_, ":utf8") for *STDOUT, *STDERR;
400 0 ▶ return if eval "eof(${p}::DATA)";
Branch: 1 branch
BranchTrueFalseTotal
if eval "eof(${p}::DATA)" 0 1 1
401 0 my $s = eval "join('', <${p}::DATA>)";
402 0 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 1 1
403 0 eval $s;
404 0 ▶ $@ and die $@;
Branch: 1 branch
BranchTrueFalseTotal
$@ and die $@ 0 1 1
405 0 1
406 }
407  
408 test unless caller;
409  
410 1;
411 # podDocumentation
412 __DATA__
↑ Summary blib/lib/MakeWithPerl.pm »