blib/lib/POSIX/1003/Module.pm

filter: Statementstmt 83.8% 88 / 105 Branchbran 59.5% 25 / 42 Conditioncond 56.6% 17 / 30 MC/DCmcdc 38.8% 7 / 18 Subroutinesub 84.2% 16 / 19 Podpod 100% 1 / 1 totaltotal 71.6% 154 / 215 CC 36 SCAR 34.2
CC
36
Cov
73%
import
48.0
exampleValue
19.5
__ANON__
2.0
CRAP 30.6
« blib/lib/POSIX/1003/Fcntl.pm ↑ Summary blib/lib/POSIX/1003.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  
9 package POSIX::1003::Module;
10 26 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 26 $VERSION = '1.02';
12  
13  
14 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 # The VERSION of the distribution is sourced from this file, because
18 # this module also loads the XS extension. Therefore, Makefile.PL
19 # extracts the version from the line below.
20 26 our $VERSION = '1.02';
21 26 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # some other modules used by the program which uses POSIX::1003 may
24 # need POSIX.xs via POSIX.
25 26 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 26 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 26 XSLoader::load 'POSIX::1003', $VERSION;
29  
30  
31 sub import(@)
32 122 ▶{ my $class = shift;
Subroutine import: called CC=32 SCAR=38.7
33 122 ▶ return if $class eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 0 122 122
34  
35 26 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 26 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 122 ▶ my $tags = \%{"${class}::EXPORT_TAGS"} or die;
Branch: 1 branch
BranchTrueFalseTotal
my $tags = \%{"${class}::EXPORT_TAGS";} or die 122 0 122
39  
40 # A hash-lookup is faster than an array lookup, so %EXPORT_OK
41 122 %{"${class}::EXPORT_OK"} = ();
42 122 my $ok = \%{"${class}::EXPORT_OK"};
43 122 ▶ unless(keys %$ok)
Branch: 1 branch
BranchTrueFalseTotal
unless (keys %$ok) 122 0 122
44 122 { @{$ok}{@{$tags->{$_}}} = () for keys %$tags;
45 }
46  
47 122 ▶ my $level = @_ && $_[0] =~ m/^\+(\d+)$/ ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ && $_[0] =~ /^\+(\d+)$/ ? : 2 120 122
Condition100%3/3
@_ and $_[0] =~ /^\+(\d+)$/
!ll&&!rl&&r
111092
MC/DC100%2/2
@_ and $_[0] =~ /^\+(\d+)$/
@_ $_[0] =~ /^\+(\d+)$/
Truth table100%3/3
A and B
A= @_B= $_[0] =~ /^\+(\d+)$/
ABresult
0X0
100
111
48 122 ▶ return if @_==1 && $_[0] eq ':none';
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and $_[0] eq ":none" 59 63 122
Condition100%3/3
@_ == 1 and $_[0] eq ":none"
!ll&&!rl&&r
392459
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
49 63 ▶ @_ = ':all' if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 11 52 63
50  
51 63 my %take;
52 63 foreach (@_)
53 109 ▶ { if( $_ eq ':all')
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq ':all') { } 12 97 109
elsif (/^:(.*)/) { } 3 94 97
54 12 { @take{keys %$ok} = ();
55 }
56 elsif( m/^:(.*)/ )
57 3 ▶ { my $tag = $tags->{$1} or croak "$class does not export $_";
Branch: 1 branch
BranchTrueFalseTotal
my $tag = $tags->{$1} or croak("$class does not export $_") 3 0 3
58 3 @take{@$tag} = ();
59 }
60 else
61 94 ▶ { is_missing($_) or exists $ok->{$_}
Branch: 1 branch
BranchTrueFalseTotal
&is_missing($_) or exists $ok->{$_} or croak("$class does not export $_") 94 0 94
Condition33%1/3
&is_missing($_) or exists $ok->{$_}
l!l&&r!l&&!r
0940
MC/DC0%0/2
&is_missing($_) or exists $ok->{$_}
&is_missing($_) exists $ok->{$_}
Truth table33%1/3
A or B
A= &is_missing($_)B= exists $ok->{$_}
ABresult
1X1
011
000
62 or croak "$class does not export $_";
63 94 undef $take{$_};
64 }
65 }
66  
67 63 ▶ my $in_core = \@{$class.'::IN_CORE'} || [];
Condition50%1/2
\@{$class . '::IN_CORE';} || []
l!l
630
MC/DC0%0/1
\@{$class . '::IN_CORE';} || []
\@{$class . '::IN_CORE';}
Truth table50%1/2
A
A= \@{$class . '::IN_CORE';}
Aresult
11
00
68  
69 63 my $pkg = (caller $level)[0];
70 63 foreach my $f (sort keys %take)
71 788 { my $export;
72 788 ▶ if(exists ${$class.'::'}{$f} && ($export = *{"${class}::$f"}{CODE}))
Branch: 6 branches
BranchTrueFalseTotal
if (exists do { $class . '::' }->{$f} and $export = *{"${class}::$f";}{'CODE'}) { } 171 617 788
elsif (&is_missing($f) or exists $ok->{$f} and $f =~ /^[A-Z_][A-Za-z0-9_]*$/) { } 530 87 617
elsif (not $f =~ /[^A-Z0-9_]/) { } 0 87 87
elsif ($f =~ s/^%//) { } 22 65 87
elsif ($in_core and grep(($f eq $_), @$in_core)) { } 35 30 65
elsif (exists $main::POSIX::{$f} and defined *{"POSIX::$f";}{'CODE'}) { } 30 0 30
Condition100%2/2
exists do { $class . '::' }->{$f} and $export = *{"${class}::$f";}{"CODE"}
!ll
589199
MC/DC100%1/1
exists do { $class . '::' }->{$f} and $export = *{"${class}::$f";}{"CODE"}
exists do { $class . '::' }->{$f}
Truth table100%2/2
A
A= exists do { $class . '::' }->{$f}
Aresult
00
11
73 { # reuse the already created function; might also be a function
74 # which is actually implemented in the $class namespace.
75 }
76 ▶ elsif( is_missing($f)
Condition66%4/6
&is_missing($f) or exists $ok->{$f} and $f =~ /^[A-Z_][A-Za-z0-9_]*$/
l!l&&r!l&&!r
053087
exists $ok->{$f} and $f =~ /^[A-Z_][A-Za-z0-9_]*$/
!ll&&!rl&&r
087530
MC/DC33%1/3
&is_missing($f) or exists $ok->{$f} and $f =~ /^[A-Z_][A-Za-z0-9_]*$/
&is_missing($f) exists $ok->{$f} $f =~ /^[A-Z_][A-Za-z0-9_]*$/
Truth table50%2/4
A or B and C
A= &is_missing($f)B= exists $ok->{$f}C= $f =~ /^[A-Z_][A-Za-z0-9_]*$/
ABCresult
1XX1
0111
00X0
0100
77 || (exists $ok->{$f} && $f =~ /^[A-Z_][A-Za-z0-9_]*$/))
78 530 { *{$class.'::'.$f} = $export = $class->_create_constant($f);
79 }
80 elsif( $f !~ m/[^A-Z0-9_]/ ) # faster than: $f =~ m!^[A-Z0-9_]+$!
81 { # other all-caps names are always from POSIX.xs
82 #XXX MO: there should be any external names left
83 #warn "$f from POSIX.pm";
84 0 ▶ if(exists $POSIX::{$f} && defined *{"POSIX::$f"}{CODE})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $main::POSIX::{$f} and defined *{"POSIX::$f";}{'CODE'}) { } 0 0 0
Condition0%0/3
exists $main::POSIX::{$f} and defined *{"POSIX::$f";}{"CODE"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $main::POSIX::{$f} and defined *{"POSIX::$f";}{"CODE"}
exists $main::POSIX::{$f} defined *{"POSIX::$f";}{"CODE"}
Truth table0%0/3
A and B
A= exists $main::POSIX::{$f}B= defined *{"POSIX::$f";}{"CODE"}
ABresult
0X0
100
111
85 { # POSIX.xs croaks on undefined constants, we will return undef
86 0 my $const = eval "POSIX::$f()";
87 0 *{$class.'::'.$f} = $export
88 0 ▶ = defined $const ? sub() {$const} : sub() {undef};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
defined $const ? : 0 0 0
89 }
90 else
91 { # ignore the missing value
92 # warn "missing constant in POSIX.pm $f" && next;
93 0 *{$class.'::'.$f} = $export = sub() {undef};
94 }
95 }
96 elsif($f =~ s/^%//)
97 22 { $export = \%{"${class}::$f"};
98 }
99 ▶ elsif($in_core && grep $f eq $_, @$in_core)
Condition66%2/3
$in_core and grep(($f eq $_), @$in_core)
!ll&&!rl&&r
03035
MC/DC50%1/2
$in_core and grep(($f eq $_), @$in_core)
$in_core grep(($f eq $_), @$in_core)
Truth table66%2/3
A and B
A= $in_coreB= grep(($f eq $_), @$in_core)
ABresult
0X0
100
111
100 { # function is in core, simply ignore the export
101 35 next;
102 }
103 30 ▶ elsif(exists $POSIX::{$f} && defined *{"POSIX::$f"}{CODE})
Condition33%1/3
exists $main::POSIX::{$f} and defined *{"POSIX::$f";}{"CODE"}
!ll&&!rl&&r
0030
MC/DC0%0/2
exists $main::POSIX::{$f} and defined *{"POSIX::$f";}{"CODE"}
exists $main::POSIX::{$f} defined *{"POSIX::$f";}{"CODE"}
Truth table33%1/3
A and B
A= exists $main::POSIX::{$f}B= defined *{"POSIX::$f";}{"CODE"}
ABresult
0X0
100
111
104 { # normal functions implemented in POSIX.xs
105 30 *{"${class}::$f"} = $export = *{"POSIX::$f"}{CODE};
106 }
107 else
108 0 { croak "unable to load $f from $class";
109 }
110  
111 26 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
112 753 *{"${pkg}::$f"} = $export;
113 }
114 }
115  
116  
117 sub exampleValue($)
118 0 ▶{ my ($pkg, $name) = @_;
Subroutine exampleValue: not called CC=5 SCAR=29.7
Pod documented
119 26 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
120  
121 0 ▶ my $tags = \%{"$pkg\::EXPORT_TAGS"} or die;
Branch: 1 branch
BranchTrueFalseTotal
my $tags = \%{"${pkg}::EXPORT_TAGS";} or die 0 0 0
122 0 ▶ my $constants = $tags->{constants} || [];
Condition0%0/2
$tags->{'constants'} || []
l!l
00
MC/DC0%0/1
$tags->{'constants'} || []
$tags->{'constants'}
Truth table0%0/2
A
A= $tags->{'constants'}
Aresult
11
00
123 0 ▶ grep $_ eq $name, @$constants
Branch: 1 branch
BranchTrueFalseTotal
grep(($_ eq $name), @$constants) or return undef 0 0 0
124 or return undef;
125  
126 0 my $val = $pkg->_create_constant($name)->();
127 0 ▶ defined $val ? $val : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
128 }
129  
130 package POSIX::1003::ReadOnlyTable;
131 26 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
132 26 $VERSION = '1.02';
133  
134 132 ▶sub TIEHASH($) { bless $_[1], $_[0] }
Subroutine TIEHASH: called CC=1 SCAR=0.0
135 633 ▶sub FETCH($) { $_[0]->{$_[1]} }
Subroutine FETCH: called CC=1 SCAR=0.0
136 0 ▶sub EXISTS($) { exists $_[0]->{$_[1]} }
Subroutine EXISTS: not called CC=1 SCAR=6.9
137 10 ▶sub FIRSTKEY() { scalar %{$_[0]}; scalar each %{$_[0]} }
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
138 56 ▶sub NEXTKEY() { scalar each %{$_[0]} }
Subroutine NEXTKEY: called CC=1 SCAR=0.0
139  
140 26 1;
« blib/lib/POSIX/1003/Fcntl.pm ↑ Summary blib/lib/POSIX/1003.pm »