File Coverage

blib/lib/POSIX/Wide/ERRNO.pm
Criterion Covered Total %
statement 25 29 86.2
branch 2 6 33.3
condition n/a
subroutine 8 9 88.8
pod n/a
total 35 44 79.5


line stmt bran cond sub pod time code
1             # Copyright 2009, 2010, 2012, 2014 Kevin Ryde
2              
3             # This file is part of I18N-Langinfo-Wide.
4             #
5             # I18N-Langinfo-Wide is free software; you can redistribute it and/or modify
6             # it under the terms of the GNU General Public License as published by the
7             # Free Software Foundation; either version 3, or (at your option) any later
8             # version.
9             #
10             # I18N-Langinfo-Wide is distributed in the hope that it will be useful, but
11             # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12             # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13             # for more details.
14             #
15             # You should have received a copy of the GNU General Public License along
16             # with I18N-Langinfo-Wide. If not, see .
17              
18             package POSIX::Wide::ERRNO;
19 1     1   15 use 5.008001; # for utf8::is_utf8()
  1         3  
  1         32  
20 1     1   5 use strict;
  1         1  
  1         33  
21 1     1   4 use warnings;
  1         2  
  1         20  
22 1     1   4 use I18N::Langinfo::Wide;
  1         1  
  1         29  
23 1     1   4 use Scalar::Util;
  1         1  
  1         210  
24              
25             # uncomment this to run the ### lines
26             #use Smart::Comments;
27              
28             our $VERSION = 8;
29              
30             sub TIESCALAR {
31 1     1   4 my ($class) = @_;
32 1         2 my $self;
33 1         9 return bless \$self, $class;
34             }
35              
36             # dualvar() in Scalar::Util 1.22 (post perl 5.10.1) will propagate the
37             # utf8 flag on its own, for prior versions must turn it on explicitly
38             #
39             BEGIN {
40 1 50   1   1 if (do { my $u = 'x';
  1         2  
41 1         4 utf8::upgrade($u);
42 1         8 my $e = Scalar::Util::dualvar(0,$u);
43 1         5 utf8::is_utf8($e) }) {
44             ### dualvar() is utf8
45 1 50       56 eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE' or die;
46             sub FETCH {
47 4     4   1695 return Scalar::Util::dualvar
48             ($!, I18N::Langinfo::Wide::to_wide("$!"));
49             }
50             1;
51             HERE
52             } else {
53             ### dualvar() is not utf8, using _utf8_on()
54 0         0 require Encode;
55 0 0       0 eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE' or die;
56             sub FETCH {
57             my $e = Scalar::Util::dualvar
58             ($!, I18N::Langinfo::Wide::to_wide("$!"));
59             Encode::_utf8_on($e);
60             return $e;
61             }
62             1;
63             HERE
64             }
65             }
66              
67             sub STORE {
68 0     0     my ($self, $value) = @_;
69 0           $! = $value;
70             }
71              
72             1;
73             __END__