File Coverage

blib/lib/POSIX/Wide/EXTENDED_OS_ERROR.pm
Criterion Covered Total %
statement 22 26 84.6
branch 2 6 33.3
condition n/a
subroutine 7 8 87.5
pod n/a
total 31 40 77.5


line stmt bran cond sub pod time code
1             # Copyright 2009, 2010, 2012, 2014 Kevin Ryde
2              
3             # This file is part of POSIX-Wide.
4             #
5             # POSIX-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             # POSIX-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 POSIX-Wide. If not, see .
17              
18             package POSIX::Wide::EXTENDED_OS_ERROR;
19 1     1   14 use 5.008001; # for utf8::is_utf8()
  1         2  
  1         30  
20 1     1   3 use strict;
  1         1  
  1         22  
21 1     1   2 use warnings;
  1         1  
  1         19  
22 1     1   2 use Scalar::Util;
  1         1  
  1         296  
23              
24             # uncomment this to run the ### lines
25             #use Smart::Comments;
26              
27             our $VERSION = 10;
28              
29             sub TIESCALAR {
30 1     1   1 my ($class) = @_;
31 1         2 my $self;
32 1         2 return bless \$self, $class;
33             }
34              
35             # dualvar() in Scalar::Util 1.22 (post perl 5.10.1) will propagate the
36             # utf8 flag on its own, for prior versions must turn it on explicitly
37             #
38             # $^E fetching in Perl_magic_get():
39             #
40             # $^E on MacOS is GetSysErrText. Is that mac-roman maybe?
41             #
42             # $^E on VMS is sys$getmsg. Is that the selected NLS thingie?
43             #
44             # $^E on ms-dos is GetLastError.
45             #
46             # $^E on OS2 is DosGetMessage or OSO001.MSG.
47             #
48             BEGIN {
49 1 50   1   2 if (do { my $u = 'x';
  1         9  
50 1         4 utf8::upgrade($u);
51 1         4 my $e = Scalar::Util::dualvar(0,$u);
52 1         5 utf8::is_utf8($e) }) {
53             ### dualvar() is utf8
54 1 50       59 eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE' or die;
55             sub FETCH {
56 4     4   2027 return Scalar::Util::dualvar
57             ($^E, POSIX::Wide::_to_wide("$^E"));
58             }
59             1;
60             HERE
61             } else {
62             ### dualvar() is not utf8, using _utf8_on()
63 0         0 require Encode;
64 0 0       0 eval "\n#line ".(__LINE__+1)." \"".__FILE__."\"\n" . <<'HERE' or die;
65             sub FETCH {
66             my $e = Scalar::Util::dualvar
67             ($^E, POSIX::Wide::_to_wide("$^E"));
68             Encode::_utf8_on($e);
69             return $e;
70             }
71             1;
72             HERE
73             }
74             }
75              
76             sub STORE {
77 0     0     my ($self, $value) = @_;
78 0           $^E = $value;
79             }
80              
81             1;
82             __END__