File Coverage

lib/POSIX/1003/Confstr.pm
Criterion Covered Total %
statement 27 32 84.3
branch 2 6 33.3
condition 3 6 50.0
subroutine 10 12 83.3
pod 3 3 100.0
total 45 59 76.2


line stmt bran cond sub pod time code
1             # Copyrights 2011-2015 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     3   21022 use warnings;
  3         6  
  3         92  
6 3     3   13 use strict;
  3         3  
  3         109  
7              
8             package POSIX::1003::Confstr;
9 3     3   12 use vars '$VERSION';
  3         2  
  3         130  
10             $VERSION = '0.99_07';
11              
12 3     3   15 use base 'POSIX::1003::Module';
  3         3  
  3         461  
13              
14 3     3   12 use Carp 'croak';
  3         4  
  3         337  
15              
16             my @constants;
17             my @functions = qw/confstr confstr_names/;
18              
19             our %EXPORT_TAGS =
20             ( constants => \@constants
21             , functions => \@functions
22             , tables => [ '%confstr' ]
23             );
24              
25             sub confstr($);
26             my $confstr;
27             our %confstr;
28              
29             BEGIN {
30 3     3   137 $confstr = confstr_table;
31 3         37 push @constants, keys %$confstr;
32 3         20 tie %confstr, 'POSIX::1003::ReadOnlyTable', $confstr;
33             }
34              
35              
36             sub exampleValue($)
37 0     0 1 0 { my ($class, $name) = @_;
38 0 0       0 $name =~ m/^_CS_/ or return;
39 0         0 my $val = confstr $name;
40 0 0       0 defined $val ? "'$val'" : 'undef';
41             }
42              
43             #-----------------------
44              
45             sub confstr($)
46 68   50 68 1 601 { my $key = shift // return;
47 68 100       311 $key =~ /^_CS_/
48             or croak "pass the constant name as string";
49              
50 66   50     79 my $id = $confstr->{$key} // return;
51 66         226 _confstr($id);
52             }
53              
54             sub _create_constant($)
55 1     1   2 { my ($class, $name) = @_;
56 1   50 0   7 my $id = $confstr->{$name} // return sub() {undef};
  0         0  
57 1     2   5 sub() {_confstr($id)};
  2         694  
58             }
59              
60             #--------------------------
61              
62 1     1 1 386 sub confstr_names() { keys %$confstr }
63              
64             #--------------------------
65              
66             1;