manuals.PL

filter: Statementstmt 8.1% 13 / 159 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 14.2% 3 / 21 Podpod n/a totaltotal 6.5% 16 / 244 CC 23 SCAR 51.4
CC
23
Cov
6%
format_rows
380.0
produce_table
12.0
table_errno
12.0
CRAP 170.3
↑ Summary blib/lib/POSIX/1003.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 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use blib;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 my @pods = map +($_, "blib/$_"), @ARGV;
13  
14 1 my %tables =
15 ( confstr => [ 'POSIX::1003::Confstr', \&table_confstr ]
16 , errno => [ 'POSIX::1003::Errno', \&table_errno ]
17 , fcntl => [ 'POSIX::1003::Fcntl', \&table_fcntl ]
18 , fdio => [ 'POSIX::1003::FdIO', \&table_fdio ]
19 , fsys => [ 'POSIX::1003::FS', \&table_fsys ]
20 , math => [ 'POSIX::1003::Math', \&table_math ]
21 , pathconf => [ 'POSIX::1003::Pathconf', \&table_pathconf ]
22 , poll => [ 'POSIX::1003::Events', \&table_poll ]
23 , property => [ 'POSIX::1003::Properties', \&table_props ]
24 , rlimit => [ 'POSIX::1003::Limit', \&table_rlimit ]
25 , signals => [ 'POSIX::1003::Signals', \&table_signals ]
26 , sigactions=>[ 'POSIX::1003::Signals',\&table_sigactions ]
27 , sysconf => [ 'POSIX::1003::Sysconf', \&table_sysconf ]
28 , termios => [ 'POSIX::1003::Termios', \&table_termios ]
29 , ulimit => [ 'POSIX::1003::Limit', \&table_ulimit ]
30 );
31  
32 sub produce_table($$);
33 sub format_rows($$);
34  
35 1 our $pod; # sorry :(
36  
37 1 foreach $pod (sort @pods)
38 0 ▶{ $pod =~ m/\.pod$/
Branch: 1 branch
BranchTrueFalseTotal
$main::pod =~ /\.pod$/ or next 0 0 0
39 or next;
40  
41 0 ▶ open POD, '<', $pod
Branch: 1 branch
BranchTrueFalseTotal
open POD, "<", $main::pod or die "cannot read $main::pod: $!\n" 0 0 0
42 or die "cannot read $pod: $!\n";
43  
44 0 my $podtmp = "$pod.tmp";
45 0 ▶ open NEW, '>', $podtmp
Branch: 1 branch
BranchTrueFalseTotal
open NEW, ">", $podtmp or die "cannot write to ${podtmp}: $!\n" 0 0 0
46 or die "cannot write to $podtmp: $!\n";
47  
48 0 my $changes = 0;
49  
50 0 ▶ while(my $old = <POD>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $old = readline POD)) 0 0 0
51 0 { print NEW $old;
52 0 ▶ $old =~ m/^\#TABLE_(\w+)_START/
Branch: 1 branch
BranchTrueFalseTotal
$old =~ /^\#TABLE_(\w+)_START/ or next 0 0 0
53 or next;
54 0 my $table = $1;
55  
56 0 ▶ do { $old = <POD> }
Branch: 1 branch
BranchTrueFalseTotal
$old =~ /^\#TABLE_${table}_END/ or do { do { $old = readline POD } } 0 0 0
57 until $old =~ m/^\#TABLE_${table}_END/;
58  
59 0 print NEW "\n";
60 0 print NEW produce_table($pod, lc $table);
61 0 $changes++;
62  
63 0 print NEW "\n\n=for comment\n$old\n\n";
64 }
65  
66 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
67 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
68  
69 0 ▶ if($changes)
Branch: 1 branch
BranchTrueFalseTotal
if ($changes) { } 0 0 0
70 0 { unlink $pod; # Windows' rename() does not work when $dest exists
71 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
72 }
73 else
74 0 ▶ { unlink $podtmp or die "unlink $podtmp: $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $podtmp or die "unlink ${podtmp}: $!" 0 0 0
75 }
76 }
77  
78 0 ▶sub sorted(@) { sort {lc($a) cmp lc($b)} @_ }
Subroutine sorted: not called CC=1 SCAR=6.9
79  
80 sub produce_table($$)
81 0 ▶{ my ($fn, $name) = @_;
Subroutine produce_table: not called CC=3 SCAR=24.8
82 0 ▶ my $table = $tables{$name}
Branch: 1 branch
BranchTrueFalseTotal
my $table = $tables{$name} or die "unknown table $name" 0 0 0
83 or die "unknown table $name";
84  
85 0 my ($pkg, $handler) = @$table;
86 0 eval "require $pkg";
87 0 ▶ die "Compilation errors in module $pkg: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
88  
89 0 $pkg->import(':all');
90 0 $handler->($pkg);
91 }
92  
93 sub table_confstr($)
94 0 ▶{ my $pkg = shift;
Subroutine table_confstr: not called CC=1 SCAR=6.9
95 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
96 sorted confstr_names();
97 0 format_rows confstr => \@rows;
98 }
99  
100 sub table_sysconf($)
101 0 ▶{ my $pkg = shift;
Subroutine table_sysconf: not called CC=1 SCAR=6.9
102 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
103 sorted sysconf_names();
104 0 format_rows sysconf => \@rows;
105 }
106  
107 sub table_pathconf($)
108 0 ▶{ my $pkg = shift;
Subroutine table_pathconf: not called CC=1 SCAR=6.9
109 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
110 sorted pathconf_names();
111 0 format_rows pathconf => \@rows;
112 }
113  
114 sub table_rlimit($)
115 0 ▶{ my $pkg = shift;
Subroutine table_rlimit: not called CC=1 SCAR=6.9
116 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
117 sorted rlimit_names();
118 0 format_rows rlimit => \@rows;
119 }
120  
121 sub table_ulimit($)
122 0 ▶{ my $pkg = shift;
Subroutine table_ulimit: not called CC=1 SCAR=6.9
123 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
124 sorted ulimit_names();
125 0 format_rows ulimit => \@rows;
126 }
127  
128 sub table_math($)
129 0 ▶{ my $pkg = shift;
Subroutine table_math: not called CC=1 SCAR=6.9
130 0 my $constants = $POSIX::1003::Math::EXPORT_TAGS{constants};
131 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
132 sorted @$constants;
133 0 format_rows math => \@rows;
134 }
135  
136 sub table_signals($)
137 0 ▶{ my $pkg = shift;
Subroutine table_signals: not called CC=1 SCAR=6.9
138 0 my $constants = $POSIX::1003::Signals::EXPORT_TAGS{signals};
139 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
140 sorted @$constants;
141 0 format_rows signals => \@rows;
142 }
143  
144 sub table_sigactions($)
145 0 ▶{ my $pkg = shift;
Subroutine table_sigactions: not called CC=1 SCAR=6.9
146 0 my $constants = $POSIX::1003::Signals::EXPORT_TAGS{actions};
147 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
148 sorted @$constants;
149 0 format_rows actions => \@rows;
150 }
151  
152 sub table_fcntl($)
153 0 ▶{ my $pkg = shift;
Subroutine table_fcntl: not called CC=1 SCAR=6.9
154 0 my $constants = $POSIX::1003::Fcntl::EXPORT_TAGS{constants};
155 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
156 sorted @$constants;
157 0 format_rows fcntl => \@rows;
158 }
159  
160 sub table_fdio($)
161 0 ▶{ my $pkg = shift;
Subroutine table_fdio: not called CC=1 SCAR=6.9
162 0 my $constants = $POSIX::1003::FdIO::EXPORT_TAGS{constants};
163 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
164 sorted @$constants;
165 0 format_rows fdio => \@rows;
166 }
167  
168 sub table_fsys($)
169 0 ▶{ my $pkg = shift;
Subroutine table_fsys: not called CC=1 SCAR=6.9
170 0 my $constants = $POSIX::1003::FS::EXPORT_TAGS{constants};
171 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
172 sorted @$constants;
173 0 format_rows fsys => \@rows;
174 }
175  
176 sub table_termios($)
177 0 ▶{ my $pkg = shift;
Subroutine table_termios: not called CC=1 SCAR=6.9
178 0 my $constants = $POSIX::1003::Termios::EXPORT_TAGS{constants};
179 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
180 sorted @$constants;
181 0 format_rows termios => \@rows;
182 }
183  
184 sub table_poll($)
185 0 ▶{ my $pkg = shift;
Subroutine table_poll: not called CC=1 SCAR=6.9
186 0 my $poll = $POSIX::1003::Events::EXPORT_TAGS{constants};
187 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
188 sorted grep /^POLL/, sort @$poll;
189 0 format_rows poll => \@rows;
190 }
191  
192 sub table_props($)
193 0 ▶{ my $pkg = shift;
Subroutine table_props: not called CC=1 SCAR=6.9
194 0 my $constants = $POSIX::1003::Properties::EXPORT_TAGS{constants};
195 0 my @rows = map { [$_, $pkg->exampleValue($_)] }
196 sorted @$constants;
197 0 format_rows property => \@rows;
198 }
199  
200 sub table_errno($)
201 0 ▶{ my $pkg = shift;
Subroutine table_errno: not called CC=3 SCAR=24.8
202 0 my $constants = $POSIX::1003::Errno::EXPORT_TAGS{constants};
203 0 my @rows;
204 0 foreach my $err (sorted @$constants)
205 0 { my $val = $pkg->exampleValue($err);
206 0 ▶ my $str = strerror($val // 'undef');
Condition0%0/2
$val // "undef"
l!l
00
MC/DC0%0/1
$val // "undef"
$val
Truth table0%0/2
A
A= $val
Aresult
11
00
207 0 push @rows, [$err, $val, $str];
208 }
209 0 format_rows errno => \@rows;
210 }
211  
212 sub format_rows($$)
213 0 ▶{ my ($manual, $rows) = @_;
Subroutine format_rows: not called CC=19 SCAR=59.4
214  
215 0 my $longest_name = 0;
216 0 my $longest_val = 5; # at least 'undef'
217 0 my $longest_more = 0;
218  
219 0 my $nr_rows = @$rows;
220 0 my $nr_undef = 0;
221  
222 0 for (@$rows)
223 0 ▶ { $longest_name = length $_->[0] if $longest_name < length $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $longest_name < length $_->[0] 0 0 0
224 0 ▶ $longest_val = length $_->[1] if $longest_val < length $_->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $longest_val < length $_->[1] 0 0 0
225 0 ▶ $longest_more = length $_->[2]
Branch: 1 branch
BranchTrueFalseTotal
if @$_ > 2 and $longest_more < length $_->[2] 0 0 0
Condition0%0/3
@$_ > 2 and $longest_more < length $_->[2]
!ll&&!rl&&r
000
MC/DC0%0/2
@$_ > 2 and $longest_more < length $_->[2]
@$_ > 2 $longest_more < length $_->[2]
Truth table0%0/3
A and B
A= @$_ > 2B= $longest_more < length $_->[2]
ABresult
0X0
100
111
226 if @$_ > 2 && $longest_more < length $_->[2];
227 }
228  
229 0 my $longest_row = 0;
230 0 my @lines;
231 0 foreach (@$rows)
232 0 { my ($name, $value, $more) = @$_;
233 0 $name .= ' ' x ($longest_name - length $name);
234 0 my $line = "$name $value";
235 0 ▶ if($longest_more)
Branch: 1 branch
BranchTrueFalseTotal
if ($longest_more) 0 0 0
236 0 { $line .= ' ' x ($longest_val - length $value);
237 0 $line .= $more;
238 }
239 0 push @lines, $line;
240 0 ▶ $longest_row = length $line if $longest_row < length $line;
Branch: 1 branch
BranchTrueFalseTotal
if $longest_row < length $line 0 0 0
241 0 ▶ $nr_undef++ if $value eq 'undef';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "undef" 0 0 0
242 }
243  
244 0 ▶ if($longest_row < 20)
Branch: 2 branches
BranchTrueFalseTotal
if ($longest_row < 20) { } 0 0 0
elsif ($longest_row < 30) { } 0 0 0
245 0 ▶ { push @lines, '' while @lines %3;
Branch: 1 branch
BranchTrueFalseTotal
@lines % 3 and do { push @lines, "" } 0 0 0
246 0 my $rows = @lines / 3;
247 0 my @left = splice @lines, 0, $rows;
248 0 chomp @left;
249 0 my @middle = splice @lines, 0, $rows;
250 0 chomp @middle;
251 0 my @right = @lines;
252 0 @lines = ();
253 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
254 , shift @left, shift @middle, shift @right
255 while @left;
256 }
257 elsif($longest_row < 30)
258 0 ▶ { push @lines, '' if @lines %2;
Branch: 1 branch
BranchTrueFalseTotal
if @lines % 2 0 0 0
259 0 my @left = splice @lines, 0, @lines/2;
260 0 my @right = @lines;
261 0 @lines = ();
262 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
263 while @left;
264 }
265  
266 0 ▶ warn sprintf "module %-8s has %3d constants, %2d are undefined\n",
Branch: 1 branch
BranchTrueFalseTotal
unless $main::pod =~ /blib/ 0 0 0
267 $manual, $nr_rows, $nr_undef
268 if $pod !~ m/blib/;
269  
270 0 ▶ if(@lines)
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 0 0 0
271 0 { my $text = " ".join("\n ", @lines)."\n";
272 0 ▶ warn $text if $ENV{AUTOMATED_TESTING};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"AUTOMATED_TESTING"} 0 0 0
273 0 return $text;
274 }
275  
276 0 <<_NONE;
277 There were no symbols detected for this category during installation.
278 This can mean that the related command is not supported, or that this
279 module did not get ported to (your version of) your Operating System.
280 In the latter case, please help us making it work.
281 _NONE
282 }
↑ Summary blib/lib/POSIX/1003.pm »