blib/lib/POSIX/1003/Limit.pm

filter: Statementstmt 82.5% 66 / 80 Branchbran 50.0% 15 / 30 Conditioncond 36.8% 7 / 19 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 89.4% 17 / 19 Podpod 66.6% 6 / 9 totaltotal 66.4% 111 / 167 CC 26 SCAR 30.6
CC
26
Cov
68%
exampleValue
90.0
ulimit
7.4
_create_constant
5.2
CRAP 21.4
« blib/lib/POSIX/1003.pm ↑ Summary blib/lib/POSIX/1003/Time.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::Limit;
10 6 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 $VERSION = '1.02';
12  
13 6 ▶use base 'POSIX::1003::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 6 my (@ulimit, @rlimit, @constants, @functions);
21 6 our %EXPORT_TAGS =
22 ( ulimit => \@ulimit
23 , rlimit => \@rlimit
24 , constants => \@constants
25 , functions => \@functions
26 , tables => [ qw/%ulimit %rlimit/ ]
27 );
28  
29 6 my ($ulimit, $rlimit);
30 6 our (%ulimit, %rlimit);
31 6 my ($rlim_saved_max, $rlim_saved_cur, $rlim_infinity);
32  
33 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 my @ufuncs = qw/ulimit ulimit_names/;
35 6 my @rfuncs = qw/getrlimit setrlimit rlimit_names/;
36 6 my @rconst = qw/RLIM_SAVED_MAX RLIM_SAVED_CUR RLIM_INFINITY/;
37  
38 6 $ulimit = ulimit_table;
39 6 @ulimit = (keys %$ulimit, @ufuncs, '%ulimit');
40 6 tie %ulimit, 'POSIX::1003::ReadOnlyTable', $ulimit;
41  
42 6 $rlimit = rlimit_table;
43 6 @rlimit = (keys %$rlimit, @rfuncs, @rconst, '%rlimit');
44 6 tie %rlimit, 'POSIX::1003::ReadOnlyTable', $rlimit;
45  
46 6 push @constants, keys %$ulimit, keys %$rlimit;
47 6 push @functions, @ufuncs, @rfuncs;
48  
49 6 $rlim_saved_max = delete $rlimit->{RLIM_SAVED_MAX};
50 6 $rlim_saved_cur = delete $rlimit->{RLIM_SAVED_CUR};
51 6 $rlim_infinity = delete $rlimit->{RLIM_INFINITY};
52 }
53  
54 3 ▶sub RLIM_SAVED_MAX { $rlim_saved_max }
Subroutine RLIM_SAVED_MAX: called CC=1 SCAR=0.0
Pod undocumented
55 2 ▶sub RLIM_SAVED_CUR { $rlim_saved_cur }
Subroutine RLIM_SAVED_CUR: called CC=1 SCAR=0.0
Pod undocumented
56 3 ▶sub RLIM_INFINITY { $rlim_infinity }
Subroutine RLIM_INFINITY: called CC=1 SCAR=0.0
Pod undocumented
57  
58 sub getrlimit($);
59 sub setrlimit($$;$);
60 sub ulimit($;$);
61  
62  
63 sub exampleValue($)
64 0 ▶{ my ($class, $name) = @_;
Subroutine exampleValue: not called CC=9 SCAR=45.0
Pod documented
65 0 ▶ if($name =~ m/^RLIMIT_/)
Branch: 4 branches
BranchTrueFalseTotal
if ($name =~ /^RLIMIT_/) { } 0 0 0
elsif ($name =~ /^RLIM_/) { } 0 0 0
elsif ($name =~ /^UL_GET|^GET_/) { } 0 0 0
elsif ($name =~ /^UL_SET|^SET_/) { } 0 0 0
66 0 { my ($soft, $hard, $success) = getrlimit $name;
67 0 for($soft,$hard)
68 0 ▶ { $_ //= 'undef';
Condition0%0/2
$_ //= "undef"
l!l
00
MC/DC0%0/1
$_ //= "undef"
$_
Truth table0%0/2
A
A= $_
Aresult
11
00
69 0 s/18446744073709551615/2**64-1/g;
70 0 s/9223372036854775807/2**63-1/g;
71 }
72 0 return "$rlimit->{$name}, $soft, $hard";
73 }
74 elsif($name =~ m/^RLIM_/)
75 0 ▶ { return $rlimit->{$name} // 'undef';
Condition0%0/2
$rlimit->{$name} // "undef"
l!l
00
MC/DC0%0/1
$rlimit->{$name} // "undef"
$rlimit->{$name}
Truth table0%0/2
A
A= $rlimit->{$name}
Aresult
11
00
76 }
77 elsif($name =~ m/^UL_GET|^GET_/)
78 0 { my $val = ulimit $name;
79 0 ▶ return defined $val ? $val : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
80 }
81 elsif($name =~ m/^UL_SET|^SET_/)
82 0 { return '(setter)';
83 }
84 else
85 0 { $class->SUPER::exampleValue($name);
86 }
87 }
88  
89  
90 sub ulimit($;$)
91 7 ▶{ my $key = shift // return;
Subroutine ulimit: called CC=7 SCAR=20.0
Pod documented
Condition50%1/2
shift() // (return)
l!l
70
MC/DC0%0/1
shift() // (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
92 7 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 6 7
93 1 ▶ { $key =~ /^UL_SET|^SET_/
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^UL_SET|^SET_/ or croak("pass the constant name as string ($key)") 1 0 1
94 or croak "pass the constant name as string ($key)";
95 1 ▶ my $id = $ulimit->{$key} // return;
Condition50%1/2
$ulimit->{$key} // (return)
l!l
10
MC/DC0%0/1
$ulimit->{$key} // (return)
$ulimit->{$key}
Truth table50%1/2
A
A= $ulimit->{$key}
Aresult
11
00
96 1 return _ulimit($id, shift);
97 }
98 else
99 6 ▶ { $key =~ /^UL_GET|^GET_/
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^UL_GET|^GET_/ or croak("pass the constant name as string ($key)") 4 2 6
100 or croak "pass the constant name as string ($key)";
101 4 ▶ my $id = $ulimit->{$key} // return;
Condition50%1/2
$ulimit->{$key} // (return)
l!l
40
MC/DC0%0/1
$ulimit->{$key} // (return)
$ulimit->{$key}
Truth table50%1/2
A
A= $ulimit->{$key}
Aresult
11
00
102 4 _ulimit($id, 0);
103 }
104 }
105  
106 sub _create_constant($)
107 20 ▶{ my ($class, $name) = @_;
Subroutine _create_constant: called CC=5 SCAR=16.6
108 20 ▶ if($name =~ m/^RLIMIT_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^RLIMIT_/) { } 18 2 20
109 18 ▶ { my $id = $rlimit->{$name} // return sub() {undef};
Condition50%1/2
$rlimit->{$name} // (return sub () { undef } )
l!l
180
MC/DC0%0/1
$rlimit->{$name} // (return sub () { undef } )
$rlimit->{$name}
Truth table50%1/2
A
A= $rlimit->{$name}
Aresult
11
00
110 18 ▶ return sub(;$$) { @_ ? _setrlimit($id, $_[0], $_[1]) : (_getrlimit($id))[0] };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 3 3
111 }
112 else
113 2 ▶ { my $id = $ulimit->{$name} // return sub() {undef};
Condition50%1/2
$ulimit->{$name} // (return sub () { undef } )
l!l
20
MC/DC0%0/1
$ulimit->{$name} // (return sub () { undef } )
$ulimit->{$name}
Truth table50%1/2
A
A= $ulimit->{$name}
Aresult
11
00
114 return $name =~ m/^UL_GET|^GET_/
115 0 ▶ ? sub() {_ulimit($id, 0)} : sub($) {_ulimit($id, shift)};
Subroutine __ANON__: called CC=1 SCAR=0.1
Subroutine __ANON__: not called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^UL_GET|^GET_/ ? : 1 1 2
116 }
117 }
118  
119  
120 sub getrlimit($)
121 21 ▶{ my $key = shift // return;
Subroutine getrlimit: called CC=4 SCAR=14.2
Pod documented
Condition50%1/2
shift() // (return)
l!l
210
MC/DC0%0/1
shift() // (return)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
122 21 ▶ $key =~ /^RLIMIT_/
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^RLIMIT_/ or croak("pass the constant name as string ($key)") 19 2 21
123 or croak "pass the constant name as string ($key)";
124
125 19 my $id = $rlimit->{$key};
126 19 ▶ defined $id ? _getrlimit($id) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 19 0 19
127 }
128  
129  
130 sub setrlimit($$;$)
131 1 ▶{ my ($key, $cur, $max) = @_;
Subroutine setrlimit: called CC=4 SCAR=15.2
Pod documented
132 1 ▶ $key =~ /^RLIMIT_/
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^RLIMIT_/ or croak("pass the constant name as string ($key)") 1 0 1
133 or croak "pass the constant name as string ($key)";
134
135 1 my $id = $rlimit->{$key};
136 1 ▶ $max //= RLIM_INFINITY;
Condition33%1/3
$max //= RLIM_INFINITY()
l!l&&r!l&&!r
010
MC/DC0%0/2
$max //= RLIM_INFINITY()
$max RLIM_INFINITY()
Truth table33%1/3
A //= B
A= $maxB= RLIM_INFINITY()
ABresult
1X1
011
000
137 1 ▶ defined $id ? _setrlimit($id, $cur, $max) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 1 0 1
138 }
139  
140  
141 1 ▶sub ulimit_names() { keys %$ulimit }
Subroutine ulimit_names: called CC=1 SCAR=0.0
Pod documented
142  
143  
144 1 ▶sub rlimit_names() { keys %$rlimit }
Subroutine rlimit_names: called CC=1 SCAR=0.0
Pod documented
145  
146  
147  
148 6 1;
« blib/lib/POSIX/1003.pm ↑ Summary blib/lib/POSIX/1003/Time.pm »