gettext_xs.pm

filter: Statementstmt 44.2% 23 / 52 Branchbran 30.0% 6 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 9 totaltotal 30.7% 32 / 104 CC 14 SCAR 27.7
CC
14
Cov
36%
bindtextdomain
30.0
nl_putenv
22.4
textdomain
2.1
CRAP 16.0
« RecodeData/US_ASCII.pm ↑ Summary Recode/_Conversions.pm »
1 #! /bin/false
2  
3 # vim: tabstop=4
4  
5 # Perl XS implementation of Uniforum message translation.
6 # Copyright (C) 2002-2026 Guido Flohr <guido.flohr@cantanea.com>,
7 # all rights reserved.
8  
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13  
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18  
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21  
22 package Locale::gettext_xs;
23  
24 25 require DynaLoader;
25 25 require Exporter;
26  
27 25 ▶use vars qw (%EXPORT_TAGS @EXPORT_OK @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 25 %EXPORT_TAGS = (locale_h => [ qw (
30 gettext
31 dgettext
32 dcgettext
33 ngettext
34 dngettext
35 dcngettext
36 pgettext
37 dpgettext
38 dcpgettext
39 npgettext
40 dnpgettext
41 dcnpgettext
42 textdomain
43 bindtextdomain
44 bind_textdomain_codeset
45 )
46 ],
47 libintl_h => [ qw (LC_CTYPE
48 LC_NUMERIC
49 LC_TIME
50 LC_COLLATE
51 LC_MONETARY
52 LC_MESSAGES
53 LC_ALL)
54 ],
55 );
56  
57 25 @EXPORT_OK = qw (gettext
58 dgettext
59 dcgettext
60 ngettext
61 dngettext
62 dcngettext
63 pgettext
64 dpgettext
65 dcpgettext
66 npgettext
67 dnpgettext
68 dcnpgettext
69 textdomain
70 bindtextdomain
71 bind_textdomain_codeset
72 nl_putenv
73 setlocale
74 LC_CTYPE
75 LC_NUMERIC
76 LC_TIME
77 LC_COLLATE
78 LC_MONETARY
79 LC_MESSAGES
80 LC_ALL);
81 25 @ISA = qw (Exporter DynaLoader);
82  
83 25 bootstrap Locale::gettext_xs;
84  
85 25 require File::Spec;
86  
87 # Reimplement pgettext functions
88 0 ▶sub pgettext ($$) {
Subroutine pgettext: not called CC=1 SCAR=6.9
Pod undocumented
89 0 my ($msgctxt, $msgid) = @_;
90  
91 0 my $msg_ctxt_id = join("\004", $msgctxt, $msgid);
92 0 return Locale::gettext_xs::_pgettext_aux
93 ("", $msg_ctxt_id, $msgid, Locale::gettext_xs::LC_MESSAGES());
94 }
95 0 ▶sub dpgettext ($$$) {
Subroutine dpgettext: not called CC=1 SCAR=6.9
Pod undocumented
96 0 my ($domain, $msgctxt, $msgid) = @_;
97  
98 0 my $msg_ctxt_id = join("\004", $msgctxt, $msgid);
99 0 return Locale::gettext_xs::_pgettext_aux
100 ($domain, $msg_ctxt_id, $msgid, Locale::gettext_xs::LC_MESSAGES());
101 }
102 0 ▶sub dcpgettext ($$$$) {
Subroutine dcpgettext: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my ($domain, $msgctxt, $msgid, $category) = @_;
104  
105 0 my $msg_ctxt_id = join("\004", $msgctxt, $msgid);
106 0 return Locale::gettext_xs::_pgettext_aux
107 ($domain, $msg_ctxt_id, $msgid, $category);
108 }
109  
110 # Reimplement npgettext functions
111 0 ▶sub npgettext ($$$$) {
Subroutine npgettext: not called CC=1 SCAR=6.9
Pod undocumented
112 0 my ($msgctxt, $msgid1, $msgid2, $n) = @_;
113  
114 0 my $msg_ctxt_id = join("\004", $msgctxt, $msgid1);
115 0 return Locale::gettext_xs::_npgettext_aux
116 ("", $msg_ctxt_id, $msgid1, $msgid2, $n, Locale::gettext_xs::LC_MESSAGES());
117 }
118 0 ▶sub dnpgettext ($$$$$) {
Subroutine dnpgettext: not called CC=1 SCAR=6.9
Pod undocumented
119 0 my ($domain, $msgctxt, $msgid1, $msgid2, $n) = @_;
120  
121 0 my $msg_ctxt_id = join("\004", $msgctxt, $msgid1);
122 0 return Locale::gettext_xs::_npgettext_aux
123 ($domain, $msg_ctxt_id, $msgid1, $msgid2, $n, Locale::gettext_xs::LC_MESSAGES());
124 }
125 0 ▶sub dcnpgettext ($$$$$$) {
Subroutine dcnpgettext: not called CC=1 SCAR=6.9
Pod undocumented
126 0 my ($domain, $msgctxt, $msgid1, $msgid2, $n, $category) = @_;
127  
128 0 my $msg_ctxt_id = join("\004", $msgctxt, $msgid1);
129 0 return Locale::gettext_xs::_npgettext_aux
130 ($domain, $msg_ctxt_id, $msgid1, $msgid2, $n, $category);
131 }
132  
133 # Wrapper function that converts Perl paths to OS paths.
134 0 ▶sub bindtextdomain ($;$) {
Subroutine bindtextdomain: not called CC=5 SCAR=34.0
Pod undocumented
135 0 my ($domain, $directory) = @_;
136  
137 0 ▶ if (defined $domain && length $domain &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $domain and length $domain and defined $directory and length $directory) { } 0 0 0
Condition0%0/9
defined $domain and length $domain and defined $directory and length $directory
!ll&&!rl&&r
000
defined $domain and length $domain and defined $directory
!ll&&!rl&&r
000
defined $domain and length $domain
!ll&&!rl&&r
000
MC/DC0%0/4
defined $domain and length $domain and defined $directory and length $directory
defined $domain length $domain defined $directory length $directory
Truth table0%0/5
A and B and C and D
A= defined $domainB= length $domainC= defined $directoryD= length $directory
ABCDresult
0XXX0
10XX0
110X0
11100
11111
138 defined $directory && length $directory) {
139 0 return Locale::gettext_xs::_bindtextdomain
140 ($domain, File::Spec->catdir ($directory));
141 } else {
142 0 return &Locale::gettext_xs::_bindtextdomain;
143 }
144 }
145  
146 # In the XS version, making the prototype optional, does not work.
147 1 ▶sub textdomain (;$) {
Subroutine textdomain: called CC=2 SCAR=7.6
Pod undocumented
148 1 my $domain = shift;
149  
150 1 ▶ if (defined $domain) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $domain) { } 0 1 1
151 0 return Locale::gettext_xs::_textdomain ($domain);
152 } else {
153 1 return Locale::gettext_xs::_textdomain ("");
154 }
155 }
156  
157 5 ▶sub nl_putenv ($) {
Subroutine nl_putenv: called CC=9 SCAR=31.1
Pod undocumented
158 5 my ($envspec) = @_;
159
160 5 ▶ return unless defined $envspec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $envspec 0 5 5
161 5 ▶ return unless length $envspec;
Branch: 1 branch
BranchTrueFalseTotal
unless length $envspec 0 5 5
162 5 ▶ return if substr ($envspec, 0, 1) eq '=';
Branch: 1 branch
BranchTrueFalseTotal
if substr($envspec, 0, 1) eq "=" 0 5 5
163
164 5 my ($var, $value) = split /=/, $envspec, 2;
165
166 5 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 5 5
167 0 ▶ $value = '' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
168 0 ▶ return unless Locale::gettext_xs::_nl_putenv ("$var=$value") == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless &_nl_putenv("$var=$value") == 0 0 0 0
169 0 ▶ if (length $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $value) { } 0 0 0
170 0 $ENV{$var} = $value;
171 } else {
172 0 delete $ENV{$var};
173 }
174 } else {
175 5 ▶ if (defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 5 0 5
176 5 $ENV{$var} = $value;
177 } else {
178 0 delete $ENV{$var};
179 }
180 }
181  
182 5 return 1;
183 }
184  
185 25 1;
186  
187 __END__
« RecodeData/US_ASCII.pm ↑ Summary Recode/_Conversions.pm »