File Coverage

lib/POSIX/1003/Sysconf.pm
Criterion Covered Total %
statement 28 32 87.5
branch 2 6 33.3
condition 5 8 62.5
subroutine 10 11 90.9
pod 3 3 100.0
total 48 60 80.0


line stmt bran cond sub pod time code
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::Sysconf;
10 3     3   71228 use vars '$VERSION';
  3         20  
  3         195  
11             $VERSION = '1.02';
12              
13 3     3   19 use base 'POSIX::1003::Module';
  3         5  
  3         608  
14              
15 3     3   19 use warnings;
  3         5  
  3         72  
16 3     3   15 use strict;
  3         6  
  3         78  
17              
18 3     3   15 use Carp 'croak';
  3         15  
  3         438  
19              
20             my @constants;
21             my @functions = qw/sysconf sysconf_names/;
22              
23             our %EXPORT_TAGS =
24             ( constants => \@constants
25             , functions => \@functions
26             , tables => [ '%sysconf' ]
27             );
28              
29             my $sysconf;
30             our %sysconf;
31              
32             BEGIN {
33 3     3   467 $sysconf = sysconf_table;
34 3         190 push @constants, keys %$sysconf;
35 3         51 tie %sysconf, 'POSIX::1003::ReadOnlyTable', $sysconf;
36             }
37              
38             sub sysconf($);
39              
40              
41             sub exampleValue($)
42 0     0 1 0 { my ($class, $name) = @_;
43 0 0       0 $name =~ m/^_SC_/ or return;
44 0         0 my $val = sysconf $name;
45 0 0       0 defined $val ? $val : 'undef';
46             }
47              
48              
49             sub sysconf($)
50 219   50 219 1 2459 { my $key = shift // return;
51 219 100       893 $key =~ /^_SC_/
52             or croak "pass the constant name as string";
53            
54 217   50     397 my $id = $sysconf->{$key} // return;
55 217   100     906 my $val = POSIX::sysconf($id) // return;
56 139         263 $val+0; # remove " but true" from "0"
57             }
58              
59             sub _create_constant($)
60 1     1   3 { my ($class, $name) = @_;
61 1   50     8 my $id = $sysconf->{$name} // return sub() {undef};
62 1     2   5 sub() {POSIX::sysconf($id)};
  2         1436  
63             }
64              
65              
66 1     1 1 844 sub sysconf_names() { keys %$sysconf }
67              
68              
69             1;