blib/lib/POSIX/1003.pm

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