blib/lib/POSIX/1003.pm

filter: Statementstmt 76.5% 98 / 128 Branchbran 67.3% 35 / 52 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 93.7% 15 / 16 Podpod 100% 3 / 3 totaltotal 75.7% 162 / 214 CC 43 SCAR 33.6
CC
43
Cov
74%
import
56.0
posix_1003_names
10.0
show_posix_names
8.5
CRAP 28.9
« blib/lib/POSIX/1003/Module.pm ↑ Summary blib/lib/POSIX/1003/Limit.pm »
1 # Copyrights 2011-2020 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution POSIX-1003. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8 package POSIX::1003;
9 4 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 $VERSION = '1.02';
11  
12  
13 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 4 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use POSIX::1003::Module (); # preload
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 my %own_functions = map +($_ => 1), qw/
20 posix_1003_modules
21 posix_1003_names
22 show_posix_names
23 /;
24  
25 4 our (%EXPORT_TAGS, %IMPORT_FROM, %SUBSET);
26  
27  
28 4 my %tags =
29 ( confstr => 'POSIX::1003::Confstr'
30 , cs => 'POSIX::1003::Confstr'
31 , errno => 'POSIX::1003::Errno'
32 , errors => 'POSIX::1003::Errno'
33 , events => 'POSIX::1003::Events'
34 , ev => 'POSIX::1003::Events'
35 , fcntl => 'POSIX::1003::Fcntl'
36 , fdio => 'POSIX::1003::FdIO'
37 , fd => 'POSIX::1003::FdIO'
38 , filesystem => 'POSIX::1003::FS'
39 , fs => 'POSIX::1003::FS'
40 , glob => 'POSIX::1003::FS'
41 , limit => 'POSIX::1003::Limit'
42 , limits => 'POSIX::1003::Limit'
43 , locale => 'POSIX::1003::Locale'
44 , math => 'POSIX::1003::Math'
45 , os => 'POSIX::1003::OS'
46 , opsys => 'POSIX::1003::OS'
47 , pathconf => 'POSIX::1003::Pathconf'
48 , pc => 'POSIX::1003::Pathconf'
49 , processes => 'POSIX::1003::Proc'
50 , proc => 'POSIX::1003::Proc'
51 , properties => 'POSIX::1003::Properties'
52 , property => 'POSIX::1003::Properties'
53 , props => 'POSIX::1003::Properties'
54 , posix => 'POSIX::1003::Properties'
55 , sc => 'POSIX::1003::Sysconf'
56 , sigaction => 'POSIX::SigAction'
57 , signals => [qw/POSIX::1003::Signals POSIX::SigSet POSIX::SigAction/]
58 , sigset => 'POSIX::SigSet'
59 , socket => 'POSIX::1003::Socket'
60 , sysconf => 'POSIX::1003::Sysconf'
61 , termio => 'POSIX::1003::Termios'
62 , termios => 'POSIX::1003::Termios'
63 , time => 'POSIX::1003::Time'
64 , user => 'POSIX::1003::User'
65 );
66  
67 4 my %mod_tag;
68 4 ▶while(my ($tag, $pkg) = each %tags)
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %tags) 144 4 148
69 144 ▶{ $pkg = $pkg->[0] if ref $pkg eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $pkg eq "ARRAY" 4 140 144
70 $mod_tag{$pkg} = $tag
71 if !$mod_tag{$pkg}
72 144 ▶ || length $mod_tag{$pkg} < length $tag;
Branch: 1 branch
BranchTrueFalseTotal
if not $mod_tag{$pkg} or length $mod_tag{$pkg} < length $tag 116 28 144
Condition100%3/3
not $mod_tag{$pkg} or length $mod_tag{$pkg} < length $tag
l!l&&r!l&&!r
843228
MC/DC100%2/2
not $mod_tag{$pkg} or length $mod_tag{$pkg} < length $tag
not $mod_tag{$pkg} length $mod_tag{$pkg} < length $tag
Truth table100%3/3
not(A) or B
A= not $mod_tag{$pkg}B= length $mod_tag{$pkg} < length $tag
ABresult
1X1
011
000
73 }
74  
75 4 { eval "require POSIX::1003::Symbols";
76 4 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
77 }
78  
79 4 ▶while(my ($pkg, $tag) = each %mod_tag) # unique modules
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %mod_tag) 84 4 88
80 84 { $IMPORT_FROM{$_} = $tag for @{$EXPORT_TAGS{$tag}};
81 }
82  
83 sub _tag2mods($)
84 118 ▶{ my $tag = shift;
Subroutine _tag2mods: called CC=3 SCAR=11.1
85 118 ▶ my $r = $tags{$tag} or croak "unknown tag '$tag'";
Branch: 1 branch
BranchTrueFalseTotal
my $r = $tags{$tag} or croak("unknown tag '${tag}'") 118 0 118
86 118 ▶ ref $r eq 'ARRAY' ? @$r : $r;
Branch: 1 branch
BranchTrueFalseTotal
ref $r eq 'ARRAY' ? : 4 114 118
87 }
88  
89 114 ▶sub _mod2tag($) { $mod_tag{$_[0]} }
Subroutine _mod2tag: called CC=1 SCAR=0.0
90 2 ▶sub _tags() { keys %tags}
Subroutine _tags: called CC=1 SCAR=0.0
91  
92 sub import(@)
93 6 ▶{ my $class = shift;
Subroutine import: called CC=27 SCAR=40.3
94 6 my (%mods, %modset, %from);
95  
96 6 ▶ my $level = @_ && $_[0] =~ /^\+(\d+)$/ ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ && $_[0] =~ /^\+(\d+)$/ ? : 0 6 6
Condition33%1/3
@_ and $_[0] =~ /^\+(\d+)$/
!ll&&!rl&&r
060
MC/DC0%0/2
@_ and $_[0] =~ /^\+(\d+)$/
@_ $_[0] =~ /^\+(\d+)$/
Truth table33%1/3
A and B
A= @_B= $_[0] =~ /^\+(\d+)$/
ABresult
0X0
100
111
97 6 ▶ return if @_==1 && $_[0] eq ':none';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $_[0] eq ":none" 1 5 6
Condition100%3/3
@_ == 1 and $_[0] eq ":none"
!ll&&!rl&&r
231
MC/DC100%2/2
@_ == 1 and $_[0] eq ":none"
@_ == 1 $_[0] eq ":none"
Truth table100%3/3
A and B
A= @_ == 1B= $_[0] eq ":none"
ABresult
0X0
100
111
98 5 ▶ @_ = ':all' if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 5 5
99  
100 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
101 4 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
102 5 my $to = (caller $level)[0];
103  
104 5 foreach (@_)
105 7 ▶ { if($_ eq ':all')
Branch: 3 branches
BranchTrueFalseTotal
if ($_ eq ':all') { } 0 7 7
elsif (/^\:(.*)/) { } 1 6 7
elsif ($own_functions{$_}) { } 5 1 6
106 0 { $mods{$_}++ for values %mod_tag;
107 0 *{$to.'::'.$_} = \&$_ for keys %own_functions;
108 }
109 elsif(m/^\:(.*)/)
110 1 ▶ { if(exists $tags{$1})
Branch: 2 branches
BranchTrueFalseTotal
if (exists $tags{$1}) { } 1 0 1
elsif (my $subset = $POSIX::1003::SUBSET{$1}) { } 0 0 0
111 { # module by longest alias
112 1 $mods{$_}++ for map $mod_tag{$_}, _tag2mods $1;
113 }
114 elsif(my $subset = $SUBSET{$1})
115 0 { push @{$modset{$subset}}, $1;
116 }
117 0 else { croak "unknown tag '$_'" };
118 }
119 elsif($own_functions{$_})
120 5 { *{$to.'::'.$_} = \&$_;
121 }
122 else
123 1 ▶ { my $mod = $IMPORT_FROM{$_} or croak "unknown symbol '$_'";
Branch: 1 branch
BranchTrueFalseTotal
my $mod = $POSIX::1003::IMPORT_FROM{$_} or croak("unknown symbol '${_}'") 1 0 1
124 1 push @{$from{$mod}}, $_;
125 }
126 }
127  
128 # no need for separate symbols when we need all
129 5 delete $from{$_} for keys %mods;
130  
131 #print "from $_ all\n" for keys %mods;
132 #print "from $_ @{$from{$_}}\n" for keys %from;
133  
134 5 my $up = '+' . ($level+1);
135 5 foreach my $tag (keys %mods) # whole tags
136 1 { delete $modset{$tag};
137 1 delete $from{$tag};
138 1 foreach my $pkg (_tag2mods($tag))
139 1 ▶ { eval "require $pkg"; die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
140 1 $pkg->import($up, ':all');
141 }
142 }
143 5 foreach my $tag (keys %modset)
144 0 { foreach my $pkg (_tag2mods($tag))
145 0 ▶ { eval "require $pkg"; die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
146 0 my @subsets = @{$modset{$tag}};
147 0 my $et = \%{"$pkg\::EXPORT_TAGS"};
148 0 $pkg->import($up, @{$et->{$_}})
149 0 for @subsets;
150 }
151 }
152 5 foreach my $tag (keys %from) # separate symbols
153 1 { foreach my $pkg (_tag2mods($tag))
154 1 ▶ { eval "require $pkg"; die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
155 1 $pkg->import($up, @{$from{$tag}});
156 }
157 }
158 }
159  
160  
161 sub posix_1003_modules()
162 3 ▶{ my %mods;
Subroutine posix_1003_modules: called CC=4 SCAR=13.9
Pod documented
163 3 foreach my $mods (values %tags)
164 108 ▶ { $mods{$_}++ for ref $mods eq 'ARRAY' ? @$mods : $mods;
Branch: 1 branch
BranchTrueFalseTotal
ref $mods eq 'ARRAY' ? : 3 105 108
165 }
166 3 keys %mods;
167 }
168  
169  
170 sub posix_1003_names(@)
171 45 ▶{ my %names;
Subroutine posix_1003_names: called CC=10 SCAR=23.1
Pod documented
172 my @modules;
173 45 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 44 1 45
174 44 { my %mods;
175 44 foreach my $sel (@_)
176 44 ▶ { $mods{$_}++ for $sel =~ m/^:(\w+)/ ? _tag2mods($1) : $sel;
Branch: 1 branch
BranchTrueFalseTotal
$sel =~ /^:(\w+)/ ? : 43 1 44
177 }
178 44 @modules = keys %mods;
179 }
180 else
181 1 { @modules = posix_1003_modules;
182 }
183  
184 45 foreach my $pkg (@modules)
185 69 { eval "require $pkg";
186 69 ▶ $@ && next; # die?
Branch: 1 branch
BranchTrueFalseTotal
$@ and next 0 69 69
187 69 ▶ $pkg->can('import') or next;
Branch: 1 branch
BranchTrueFalseTotal
$pkg->can("import") or next 69 0 69
188 69 $pkg->import(':none'); # create %EXPORT_OK
189  
190 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
191 69 my $exports = \%{"${pkg}::EXPORT_OK"};
192 69 $names{$_} = $pkg for keys %$exports;
193 }
194  
195 45 ▶ wantarray ? keys %names : \%names;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 42 45
196 }
197  
198  
199 sub show_posix_names(@)
200 0 ▶{ my $pkg_of = posix_1003_names @_;
Subroutine show_posix_names: not called CC=3 SCAR=21.4
Pod documented
201 0 my %order = map {(my $n = lc $_) =~ s/[^A-Za-z0-9]//g; ($n => $_)}
202 keys %$pkg_of; # Swartzian transform
203  
204 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
205 0 foreach (sort keys %order)
206 0 { my $name = $order{$_};
207 0 my $pkg = $pkg_of->{$name};
208 0 $pkg->import($name);
209 0 my $val = $pkg->exampleValue($name);
210 0 (my $abbrev = $pkg) =~ s/^POSIX\:\:1003\:\:/::/;
211 0 my $mod = $mod_tag{$pkg};
212 0 ▶ if(defined $val)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
213 0 { printf "%-12s :%-10s %-30s %s\n", $abbrev, $mod, $name, $val;
214 }
215 else
216 0 { printf "%-12s :%-10s %s\n", $abbrev, $mod, $name;
217 }
218 }
219 0 print "*** ".(keys %$pkg_of)." symbols in total\n";
220 }
221  
222 #------------
223  
224 4 1;
« blib/lib/POSIX/1003/Module.pm ↑ Summary blib/lib/POSIX/1003/Limit.pm »