File Coverage

lib/POSIX/1003/Errno.pm
Criterion Covered Total %
statement 26 30 86.6
branch 3 6 50.0
condition 2 6 33.3
subroutine 10 12 83.3
pod 4 4 100.0
total 45 58 77.5


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::Errno;
10 6     6   72961 use vars '$VERSION';
  6         22  
  6         326  
11             $VERSION = '1.02';
12              
13 6     6   33 use base 'POSIX::1003::Module';
  6         18  
  6         908  
14              
15 6     6   37 use warnings;
  6         8  
  6         190  
16 6     6   33 use strict;
  6         81  
  6         160  
17              
18 6     6   31 use Carp 'croak';
  6         8  
  6         955  
19              
20             my @constants;
21             my @functions = qw/strerror errno errno_names/;
22              
23             our %EXPORT_TAGS =
24             ( constants => \@constants
25             , functions => \@functions
26             , tables => [ '%errno' ]
27             );
28              
29             my $errno;
30             our %errno;
31              
32             BEGIN {
33 6     6   518 $errno = errno_table;
34 6         250 push @constants, keys %$errno;
35 6         70 tie %errno, 'POSIX::1003::ReadOnlyTable', $errno;
36             }
37              
38             sub errno($);
39              
40              
41             sub exampleValue($)
42 0     0 1 0 { my ($class, $name) = @_;
43 0 0       0 $name =~ m/^(?:WSA)?E/ or return;
44 0   0     0 errno($name) // 'undef';
45             }
46              
47              
48 134 50   134 1 746 sub strerror($) { _strerror($_[0]) || "Unknown error $_[0]" }
49              
50              
51             sub errno($)
52 137   50 137 1 2793 { my $key = shift // return;
53 137 100       819 $key =~ /^(?:WSA)?E/
54             or croak "pass the constant name $key as string";
55            
56 135         256 $errno->{$key};
57             }
58              
59             sub _create_constant($)
60 6     6   16 { my ($class, $name) = @_;
61 6   50     47 my $nr = $errno->{$name} // return sub() {undef};
62 6     0   49 sub() {$nr};
  0         0  
63             }
64              
65              
66 1     1 1 837 sub errno_names() { keys %$errno }
67              
68              
69             1;