manuals.PL

filter: Statementstmt 23.9% 35 / 146 Branchbran 6.2% 4 / 64 Conditioncond 9.5% 2 / 21 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 25.9% 7 / 27 Podpod n/a totaltotal 17.7% 48 / 270 CC 27 SCAR 49.8
CC
27
Cov
18%
format_rows
380.0
produce_table
58.0
__ANON__
6.0
CRAP 146.0
↑ Summary blib/lib/POSIX/1003/Fcntl.pm »
1 #!/usr/bin/env perl
2 #
3 # Generate tables in manual pages and for the lazy importer POSIX::3
4 # For unclear reason, it only works when both lib and blib versions of
5 # a pod get modified.
6  
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use blib;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use POSIX qw/strerror setlocale LC_ALL/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use IO::Handle (); # required by some older Perl versions
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # please errno in english
16 2 ▶warn "LOCALE="
Condition33%2/6
setlocale(6, 'en_US.utf8') || setlocale(6, 'POSIX') || setlocale(6, 'C')
l!l&&r!l&&!r
200
setlocale(6, "en_US.utf8") or setlocale(6, "POSIX")
l!l&&r!l&&!r
020
MC/DC0%0/3
setlocale(6, 'en_US.utf8') || setlocale(6, 'POSIX') || setlocale(6, 'C')
setlocale(6, "en_US.utf8") setlocale(6, "POSIX") setlocale(6, 'C')
Truth table25%1/4
A or B || C
A= setlocale(6, "en_US.utf8")B= setlocale(6, "POSIX")C= setlocale(6, 'C')
ABCresult
1XX1
01X1
0011
0000
17 , setlocale(LC_ALL, 'en_US.utf8')
18 || setlocale(LC_ALL, 'POSIX')
19 || setlocale(LC_ALL, 'C');
20 2 my @pods = map +($_, "blib/$_"), @ARGV;
21 2 my $constindex_fn = 'constindex.txt';
22  
23 my %tables =
24 ( confstr => 'POSIX::1003::Confstr'
25 , errno =>
26 { pkg => 'POSIX::1003::Errno'
27 0 ▶ , more => sub { strerror($_[0] // 'undef') }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0] // "undef"
l!l
00
MC/DC0%0/1
$_[0] // "undef"
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
28 }
29 , fcntl => 'POSIX::1003::Fcntl'
30 , fdio => 'POSIX::1003::FdIO'
31 , fsys_stat =>
32 { pkg => 'POSIX::1003::FS'
33 0 ▶ , select => sub { $_[0] =~ m/^S_I/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 }
35 , fsys_acc =>
36 { pkg => 'POSIX::1003::FS'
37 0 ▶ , select => sub { $_[0] =~ m/_OK$|MAX/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 }
39 , fsys_glob =>
40 { pkg => 'POSIX::1003::FS'
41 0 ▶ , select => sub { $_[0] =~ m/^(?:GLOB|FNM|WRDE)_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 }
43 , locale => 'POSIX::1003::Locale'
44 , math => 'POSIX::1003::Math'
45 , os => 'POSIX::1003::OS'
46 , poll =>
47 { pkg => 'POSIX::1003::Events'
48 0 ▶ , select => sub { $_[0] =~ m/^E?POLL/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 }
50 , pathconf => 'POSIX::1003::Pathconf'
51 , property => 'POSIX::1003::Properties'
52 , proc => 'POSIX::1003::Proc'
53 , rlimit =>
54 { pkg => 'POSIX::1003::Limit'
55 0 ▶ , select => sub { $_[0] =~ m/^RLIM/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 }
57  
58 , signals =>
59 { pkg => 'POSIX::1003::Signals'
60 0 ▶ , select => sub { $_[0] !~ m/^SA_|^SIG_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
61 }
62 , sigactions =>
63 { pkg => 'POSIX::1003::Signals'
64 0 ▶ , select => sub { $_[0] =~ m/^SA_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
65 }
66 , sighandlers =>
67 { pkg => 'POSIX::1003::Signals'
68 0 ▶ , select => sub { $_[0] =~ m/^SIG_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 }
70 , socket =>
71 { pkg => 'POSIX::1003::Socket'
72 0 ▶ , select => sub { $_[0] !~ m/^(?:SOL|SO|AF|PF)_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
73 }
74 , socket_sol =>
75 { pkg => 'POSIX::1003::Socket'
76 0 ▶ , select => sub { $_[0] =~ m/^SOL_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
77 }
78 , socket_so =>
79 { pkg => 'POSIX::1003::Socket'
80 0 ▶ , select => sub { $_[0] =~ m/^SO_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
81 }
82 , socket_af =>
83 { pkg => 'POSIX::1003::Socket'
84 0 ▶ , select => sub { $_[0] =~ m/^AF_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
85 }
86 , socket_pf =>
87 { pkg => 'POSIX::1003::Socket'
88 0 ▶ , select => sub { $_[0] =~ m/^PF_/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
89 }
90  
91 , sysconf => 'POSIX::1003::Sysconf'
92 , termios => 'POSIX::1003::Termios'
93 , time => 'POSIX::1003::Time'
94 , ulimit =>
95 { pkg => 'POSIX::1003::Limit'
96 0 ▶ , select => sub { $_[0] !~ m/^RLIM/ }
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 }
98 2 );
99  
100 sub produce_table($$);
101 sub format_rows($$);
102  
103 2 my ($sum_tables, $sum_rows, $sum_undef) = (0, 0, 0);
104 sub summerize();
105  
106 2 our $pod; # sorry :(
107  
108 2 ▶open my $constindex, ">:encoding(utf8)", $constindex_fn
Branch: 1 branch
BranchTrueFalseTotal
open my $constindex, ">:encoding(utf8)", $constindex_fn or die "cannot write ${constindex_fn}: $!" 2 0 2
109 or die "cannot write $constindex_fn: $!";
110  
111 2 my $sys;
112 2 ▶if(open $sys, '<:encoding(utf8)', 'system.c')
Branch: 1 branch
BranchTrueFalseTotal
if (open $sys, "<:encoding(utf8)", "system.c") 2 0 2
113 2 { $constindex->print(<$sys>);
114 }
115 2 close $sys;
116  
117 2 foreach $pod (sort @pods)
118 {
119 2 ▶ $pod =~ m/\.pod$/ or next;
Branch: 1 branch
BranchTrueFalseTotal
$main::pod =~ /\.pod$/ or next 0 2 2
120 0 ▶ $pod =~ m/blib/ or next;
Branch: 1 branch
BranchTrueFalseTotal
$main::pod =~ /blib/ or next 0 0 0
121  
122 0 ▶ open POD, '<', $pod
Branch: 1 branch
BranchTrueFalseTotal
open POD, "<", $main::pod or die "cannot read $main::pod: $!\n" 0 0 0
123 or die "cannot read $pod: $!\n";
124  
125 0 my $podtmp = "$pod.tmp";
126 0 ▶ open NEW, '>', $podtmp
Branch: 1 branch
BranchTrueFalseTotal
open NEW, ">", $podtmp or die "cannot write to ${podtmp}: $!\n" 0 0 0
127 or die "cannot write to $podtmp: $!\n";
128  
129 0 my $changes = 0;
130  
131 0 ▶ while(my $old = <POD>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old = readline POD)) 0 0 0
132 0 { print NEW $old;
133 0 ▶ $old =~ m/^\#TABLE_(\w+)_START/
Branch: 1 branch
BranchTrueFalseTotal
$old =~ /^\#TABLE_(\w+)_START/ or next 0 0 0
134 or next;
135 0 my $table = $1;
136  
137 0 ▶ do { $old = <POD> }
Branch: 1 branch
BranchTrueFalseTotal
$old =~ /^\#TABLE_${table}_END/ or do { do { $old = readline POD } } 0 0 0
138 until $old =~ m/^\#TABLE_${table}_END/;
139  
140 0 my $line;
141 0 ▶ do { $line = <POD> }
Branch: 1 branch
BranchTrueFalseTotal
$line =~ /^\s*$/ and do { do { $line = readline POD } } 0 0 0
142 while $line =~ m/^\s*$/;
143  
144 0 print NEW "\n";
145 0 print NEW produce_table($pod, lc $table);
146 0 $changes++;
147  
148 0 print NEW "\n\n=for comment\n$old\n$line";
149 }
150  
151 0 ▶ close NEW or die "write error in $podtmp: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close NEW or die "write error in ${podtmp}: $!\n" 0 0 0
152 0 ▶ close POD or die "read error in $pod: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
close POD or die "read error in $main::pod: $!\n" 0 0 0
153  
154 0 ▶ if($changes)
Branch: 1 branch
BranchTrueFalseTotal
if ($changes) { } 0 0 0
155 0 { unlink $pod; # Windows' rename() does not work when $dest exists
156 0 ▶ rename $podtmp, $pod or die "rename $podtmp $pod: $!";
Branch: 1 branch
BranchTrueFalseTotal
rename $podtmp, $main::pod or die "rename $podtmp $main::pod: $!" 0 0 0
157 }
158 else
159 0 ▶ { unlink $podtmp or die "unlink $podtmp: $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $podtmp or die "unlink ${podtmp}: $!" 0 0 0
160 }
161 }
162  
163 2 summerize;
164  
165 2 ▶close $constindex
Branch: 1 branch
BranchTrueFalseTotal
close $constindex or die "errors at close ${constindex_fn}: $!" 2 0 2
166 or die "errors at close $constindex_fn: $!";
167  
168 2 exit 0;
169  
170 ### HELPERS
171  
172 0 ▶sub sorted(@) { sort {lc($a) cmp lc($b)} @_ }
Subroutine sorted: not called CC=1 SCAR=6.9
173  
174 sub produce_table($$)
175 0 ▶{ my ($fn, $name) = @_;
Subroutine produce_table: not called CC=8 SCAR=40.6
176 0 my $config = $tables{$name};
177 0 ▶ unless($config)
Branch: 1 branch
BranchTrueFalseTotal
unless ($config) 0 0 0
178 0 { warn "unknown table $name";
179 0 return;
180 }
181  
182 0 ▶ ref $config
Branch: 1 branch
BranchTrueFalseTotal
ref $config or $config = {"pkg", $config} 0 0 0
183 or $config = { pkg => $config };
184  
185 0 my $pkg = $config->{pkg};
186 0 eval "require $pkg";
187 0 ▶ die "Compilation errors in module $pkg: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
188  
189 0 ▶ my $subset = $config->{select} || sub { $_[0] =~ m/^[A-Z0-9_]+$/ };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$config->{'select'} || sub { $_[0] =~ /^[A-Z0-9_]+$/; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{'select'} || sub { $_[0] =~ /^[A-Z0-9_]+$/; }
$config->{'select'} sub { $_[0] =~ /^[A-Z0-9_]+$/; }
Truth table0%0/3
A || B
A= $config->{'select'}B= sub { $_[0] =~ /^[A-Z0-9_]+$/; }
ABresult
1X1
011
000
190 0 ▶ my $more = $config->{more} || sub { undef };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$config->{'more'} || sub { undef; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$config->{'more'} || sub { undef; }
$config->{'more'} sub { undef; }
Truth table0%0/3
A || B
A= $config->{'more'}B= sub { undef; }
ABresult
1X1
011
000
191  
192 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
193 0 ▶ my $consts = ${"${pkg}::EXPORT_TAGS"}{constants} || [];
Condition0%0/2
do { "${pkg}::EXPORT_TAGS" }->{'constants'} || []
l!l
00
MC/DC0%0/1
do { "${pkg}::EXPORT_TAGS" }->{'constants'} || []
do { "${pkg}::EXPORT_TAGS" }->{'constants'}
Truth table0%0/2
A
A= do { "${pkg}::EXPORT_TAGS" }->{'constants'}
Aresult
11
00
194  
195 0 my @consts = sorted grep $subset->($_), @$consts;
196 0 my @rows;
197 0 foreach my $const (@consts)
198 0 { my $val = $pkg->exampleValue($const);
199 0 push @rows, +[$const, $val, $more->($val)]
200 }
201  
202 0 format_rows $name => \@rows;
203 }
204  
205 sub format_rows($$)
206 0 ▶{ my ($manual, $rows) = @_;
Subroutine format_rows: not called CC=19 SCAR=59.4
207  
208 0 my $longest_name = 0;
209 0 my $longest_val = 5; # at least 'undef'
210 0 my $longest_more = 0;
211  
212 0 my $nr_rows = @$rows;
213 0 my $nr_undef = 0;
214  
215 0 for (@$rows)
216 0 ▶ { $longest_name = length $_->[0] if $longest_name < length $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $longest_name < length $_->[0] 0 0 0
217 0 ▶ $longest_val = length $_->[1] if $longest_val < length $_->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $longest_val < length $_->[1] 0 0 0
218 0 ▶ $longest_more = length $_->[2]
Branch: 1 branch
BranchTrueFalseTotal
if defined $_->[2] and $longest_more < length $_->[2] 0 0 0
Condition0%0/3
defined $_->[2] and $longest_more < length $_->[2]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_->[2] and $longest_more < length $_->[2]
defined $_->[2] $longest_more < length $_->[2]
Truth table0%0/3
A and B
A= defined $_->[2]B= $longest_more < length $_->[2]
ABresult
0X0
100
111
219 if defined $_->[2] && $longest_more < length $_->[2];
220 }
221  
222 0 my $longest_row = 0;
223 0 my @lines;
224 0 foreach (@$rows)
225 0 { my ($name, $value, $more) = @$_;
226 0 $name .= ' ' x ($longest_name - length $name);
227 0 my $line = "$name $value";
228 0 ▶ if($longest_more)
Branch: 1 branch
BranchTrueFalseTotal
if ($longest_more) 0 0 0
229 0 { $line .= ' ' x ($longest_val - length $value);
230 0 $line .= $more;
231 }
232 0 push @lines, $line;
233 0 ▶ $longest_row = length $line if $longest_row < length $line;
Branch: 1 branch
BranchTrueFalseTotal
if $longest_row < length $line 0 0 0
234 0 ▶ $nr_undef++ if $value eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "undef" 0 0 0
235 }
236  
237 0 ▶ if($longest_row < 20)
Branch: 2 branches
BranchTrueFalseTotal
if ($longest_row < 20) { } 0 0 0
elsif ($longest_row < 30) { } 0 0 0
238 0 ▶ { push @lines, '' while @lines %3;
Branch: 1 branch
BranchTrueFalseTotal
@lines % 3 and do { push @lines, "" } 0 0 0
239 0 my $rows = @lines / 3;
240 0 my @left = splice @lines, 0, $rows;
241 0 chomp @left;
242 0 my @middle = splice @lines, 0, $rows;
243 0 chomp @middle;
244 0 my @right = @lines;
245 0 @lines = ();
246 0 ▶ push @lines, sprintf "%-20s %-20s %s"
Branch: 1 branch
BranchTrueFalseTotal
@left and do { push @lines, sprintf("%-20s %-20s %s", shift @left, shift @middle, shift @right) } 0 0 0
247 , shift @left, shift @middle, shift @right
248 while @left;
249 }
250 elsif($longest_row < 30)
251 0 ▶ { push @lines, '' if @lines %2;
Branch: 1 branch
BranchTrueFalseTotal
if @lines % 2 0 0 0
252 0 my @left = splice @lines, 0, @lines/2;
253 0 my @right = @lines;
254 0 @lines = ();
255 0 ▶ push @lines, sprintf "%-30s %s", shift @left, shift @right
Branch: 1 branch
BranchTrueFalseTotal
@left and do { push @lines, sprintf("%-30s %s", shift @left, shift @right) } 0 0 0
256 while @left;
257 }
258  
259 # if($pod !~ m/blib/)
260 0 { my $header = sprintf "table %-13s has %4d constants, %3d are undef\n"
261 , $manual, $nr_rows, $nr_undef;
262 0 warn $header;
263 0 print $constindex $header;
264 0 $sum_tables++;
265 0 $sum_rows += $nr_rows;
266 0 $sum_undef += $nr_undef;
267 }
268  
269 0 ▶ if(@lines)
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 0 0 0
270 0 { my $text = " ".join("\n ", @lines)."\n";
271  
272 print $constindex ':', join('#', map $_ // '', @$_), "\n"
273 0 ▶ for @$rows;
Condition0%0/2
$_ // ""
l!l
00
MC/DC0%0/1
$_ // ""
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
274  
275 0 return $text;
276 }
277  
278 0 <<_NONE;
279 There were no symbols detected for this category during installation.
280 This can mean that the related command is not supported, or that this
281 module did not get ported to (your version of) your Operating System.
282 In the latter case, please help us making it work.
283 _NONE
284 }
285  
286 sub summerize()
287 2 ▶{ warn sprintf " Σ %2d tables have %4d constants, %3d are undefined\n"
Subroutine summerize: called CC=1 SCAR=0.0
288 , $sum_tables, $sum_rows, $sum_undef;
289 }
↑ Summary blib/lib/POSIX/1003/Fcntl.pm »