blib/lib/I18N/Langinfo/Wide.pm

filter: Statementstmt 91.1% 31 / 34 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 89.8% 44 / 49 CC 3 SCAR 3.4
CC
3
Cov
87%
to_wide
2.1
langinfo
2.1
BEGIN
1.0
CRAP 1.4
↑ Summary
1 # Copyright 2009, 2010, 2011, 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 <http://www.gnu.org/licenses/>.
17  
18 package I18N::Langinfo::Wide;
19 1 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use I18N::Langinfo ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # version 2.25 for Encode::Alias recognise "646" on netbsd
25 1 ▶use Encode 2.25;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 our $VERSION = 9;
28  
29 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 our @ISA = ('Exporter');
31 1 our @EXPORT_OK = qw(langinfo to_wide);
32  
33 # not yet ...
34 # %EXPORT_TAGS = (all => \@EXPORT_OK);
35  
36  
37 # As of I18N::Langinfo 0.02 in perl 5.10.1 all the langinfo()s are locale
38 # character strings. The binary ones like GROUPING or P_CS_PRECEDES are not
39 # offered. (glibc categories.def sets out which is what.)
40 #
41 # exists $_byte{$key_integer} means a byte string
42 1 our %_byte;
43 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.4
44 @_byte{ # hash slice
45 0 grep {defined}
46 1 map {eval "I18N::Langinfo::$_()"}
47 qw(GROUPING
48 MON_GROUPING
49 FRAC_DIGITS
50 INT_FRAC_DIGITS
51 P_CS_PRECEDES
52 P_SEP_BY_SPACE
53 N_CS_PRECEDES
54 N_SEP_BY_SPACE
55 P_SIGN_POSN
56 N_SIGN_POSN
57 INT_P_CS_PRECEDES
58 INT_P_SEP_BY_SPACE
59 INT_N_CS_PRECEDES
60 INT_N_SEP_BY_SPACE
61 INT_P_SIGN_POSN
62 INT_N_SIGN_POSN)
63 } = ();
64 }
65  
66 97 ▶sub langinfo {
Subroutine langinfo: called CC=2 SCAR=7.4
Pod documented
67 97 my ($key) = @_;
68 97 my $str = I18N::Langinfo::langinfo($key);
69 97 ▶ if ($_byte{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($I18N::Langinfo::Wide::_byte{$key}) { } 0 97 97
70 0 return $str;
71 } else {
72 97 return to_wide($str);
73 }
74 }
75  
76 97 ▶sub to_wide {
Subroutine to_wide: called CC=2 SCAR=7.6
Pod documented
77 97 my ($str) = @_;
78 0 ▶ if (utf8::is_utf8($str)) { return $str; }
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::is_utf8($str)) 0 97 97
79  
80 # netbsd langinfo(CODESET) returns "646" meaning ISO-646, ie. ASCII. Must
81 # put that through resolve_alias() to turn it into "ascii".
82 #
83 97 return Encode::decode (Encode::resolve_alias
84 (I18N::Langinfo::langinfo
85 (I18N::Langinfo::CODESET())),
86 $str, Encode::FB_CROAK());
87 }
88  
89 1 1;
90 __END__
↑ Summary