lib/Module/Generic/Number/Format.pm

filter: Statementstmt 62.5% 430 / 688 Branchbran 37.4% 155 / 414 Conditioncond 31.9% 70 / 219 MC/DCmcdc 10.4% 13 / 124 Subroutinesub 75.2% 64 / 85 Podpod 90.5% 48 / 53 totaltotal 49.2% 780 / 1583 CC 297 SCAR 49.5
CC
297
Cov
50%
format_picture
1053.0
format_money
171.2
__ANON__
156.0
CRAP 141.8
« lib/Module/Generic/Dynamic.pm ↑ Summary lib/Module/Generic/Global.pm »
1 ##----------------------------------------------------------------------------
2 ## Module Generic - ~/lib/Module/Generic/Number/Format.pm
3 ## Version v0.1.1
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2026/07/01
7 ## Modified 2026/07/05
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Module::Generic::Number::Format;
14 BEGIN
15 2 ▶{
Subroutine BEGIN: called CC=2 SCAR=7.3
16 2 ▶ use v5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 warnings::register_categories( 'Module::Generic' );
20 2 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use vars qw( $SUPPORTED_LOCALES $DEFAULT $NUMBER_RE $LOCALE_LOCK );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 require POSIX;
24 2 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 2 0 2
25 {
26 2 POSIX->import( qw( isinf isnan ) );
27 }
28 else
29 {
30 0 my $POS_INF = 9**9**9;
31 0 my $NEG_INF = -$POS_INF;
32 *isinf = sub
33 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=18.1
34 0 ▶ return(0) if( !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
35 2 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 0 ▶ return( $_[0] == $POS_INF || $_[0] == $NEG_INF );
Condition0%0/3
$_[0] == $POS_INF || $_[0] == $NEG_INF
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] == $POS_INF || $_[0] == $NEG_INF
$_[0] == $POS_INF $_[0] == $NEG_INF
Truth table0%0/3
A || B
A= $_[0] == $POS_INFB= $_[0] == $NEG_INF
ABresult
1X1
011
000
37 0 };
38 *isnan = sub
39 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=10.1
40 0 ▶ return(0) if( !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
41 2 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 0 return( $_[0] != $_[0] );
43 0 };
44 }
45 # 2026-05-17: Regexp::Common does not install under perl v5.10.1 because of an error in its test t/test_comments.t
46 # use Regexp::Common qw( number );
47 # $NUMBER_RE = $RE{num}{real};
48 2 $NUMBER_RE = qr/(?:(?i)(?:[-+]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[-+]?)(?:[0123456789]+))|))/;
49 2 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
50 # Largest integer a 32-bit Perl can handle is based on the mantissa
51 # size of a double float, which is up to 53 bits. While we may be
52 # able to support larger values on 64-bit systems, some Perl integer
53 # operations on 64-bit integer systems still use the 53-bit-mantissa
54 # double floats. To be safe, we cap at 2**53; use Math::BigFloat
55 # instead for larger numbers.
56 2 ▶ use constant MAX_INT => 2**53;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 2 ▶ use constant HAS_THREADS => $Config{useithreads};
Subroutine BEGIN: called CC=1 SCAR=0.0
58 2 if( HAS_THREADS )
59 {
60 require threads;
61 require threads::shared;
62 threads->import();
63 threads::shared->import();
64 2 ▶ our $LOCALE_LOCK :shared;
Subroutine BEGIN: called CC=1 SCAR=0.0
65 }
66 2 our( $VERSION ) = 'v0.1.1';
67 };
68  
69 # use strict;
70 2 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 # NOTE: $SUPPORTED_LOCALES
74 2 $SUPPORTED_LOCALES =
75 {
76 aa_DJ => [qw( aa_DJ.UTF-8 aa_DJ.ISO-8859-1 aa_DJ.ISO8859-1 )],
77 aa_ER => [qw( aa_ER.UTF-8 )],
78 aa_ET => [qw( aa_ET.UTF-8 )],
79 af_ZA => [qw( af_ZA.UTF-8 af_ZA.ISO-8859-1 af_ZA.ISO8859-1 )],
80 ak_GH => [qw( ak_GH.UTF-8 )],
81 am_ET => [qw( am_ET.UTF-8 )],
82 an_ES => [qw( an_ES.UTF-8 an_ES.ISO-8859-15 an_ES.ISO8859-15 )],
83 anp_IN => [qw( anp_IN.UTF-8 )],
84 ar_AE => [qw( ar_AE.UTF-8 ar_AE.ISO-8859-6 ar_AE.ISO8859-6 )],
85 ar_BH => [qw( ar_BH.UTF-8 ar_BH.ISO-8859-6 ar_BH.ISO8859-6 )],
86 ar_DZ => [qw( ar_DZ.UTF-8 ar_DZ.ISO-8859-6 ar_DZ.ISO8859-6 )],
87 ar_EG => [qw( ar_EG.UTF-8 ar_EG.ISO-8859-6 ar_EG.ISO8859-6 )],
88 ar_IN => [qw( ar_IN.UTF-8 )],
89 ar_IQ => [qw( ar_IQ.UTF-8 ar_IQ.ISO-8859-6 ar_IQ.ISO8859-6 )],
90 ar_JO => [qw( ar_JO.UTF-8 ar_JO.ISO-8859-6 ar_JO.ISO8859-6 )],
91 ar_KW => [qw( ar_KW.UTF-8 ar_KW.ISO-8859-6 ar_KW.ISO8859-6 )],
92 ar_LB => [qw( ar_LB.UTF-8 ar_LB.ISO-8859-6 ar_LB.ISO8859-6 )],
93 ar_LY => [qw( ar_LY.UTF-8 ar_LY.ISO-8859-6 ar_LY.ISO8859-6 )],
94 ar_MA => [qw( ar_MA.UTF-8 ar_MA.ISO-8859-6 ar_MA.ISO8859-6 )],
95 ar_OM => [qw( ar_OM.UTF-8 ar_OM.ISO-8859-6 ar_OM.ISO8859-6 )],
96 ar_QA => [qw( ar_QA.UTF-8 ar_QA.ISO-8859-6 ar_QA.ISO8859-6 )],
97 ar_SA => [qw( ar_SA.UTF-8 ar_SA.ISO-8859-6 ar_SA.ISO8859-6 )],
98 ar_SD => [qw( ar_SD.UTF-8 ar_SD.ISO-8859-6 ar_SD.ISO8859-6 )],
99 ar_SS => [qw( ar_SS.UTF-8 )],
100 ar_SY => [qw( ar_SY.UTF-8 ar_SY.ISO-8859-6 ar_SY.ISO8859-6 )],
101 ar_TN => [qw( ar_TN.UTF-8 ar_TN.ISO-8859-6 ar_TN.ISO8859-6 )],
102 ar_YE => [qw( ar_YE.UTF-8 ar_YE.ISO-8859-6 ar_YE.ISO8859-6 )],
103 as_IN => [qw( as_IN.UTF-8 )],
104 ast_ES => [qw( ast_ES.UTF-8 ast_ES.ISO-8859-15 ast_ES.ISO8859-15 )],
105 ayc_PE => [qw( ayc_PE.UTF-8 )],
106 az_AZ => [qw( az_AZ.UTF-8 )],
107 be_BY => [qw( be_BY.UTF-8 be_BY.CP1251 )],
108 bem_ZM => [qw( bem_ZM.UTF-8 )],
109 ber_DZ => [qw( ber_DZ.UTF-8 )],
110 ber_MA => [qw( ber_MA.UTF-8 )],
111 bg_BG => [qw( bg_BG.UTF-8 bg_BG.CP1251 )],
112 bhb_IN => [qw( bhb_IN.UTF-8 )],
113 bho_IN => [qw( bho_IN.UTF-8 )],
114 bn_BD => [qw( bn_BD.UTF-8 )],
115 bn_IN => [qw( bn_IN.UTF-8 )],
116 bo_CN => [qw( bo_CN.UTF-8 )],
117 bo_IN => [qw( bo_IN.UTF-8 )],
118 br_FR => [qw( br_FR.UTF-8 br_FR.ISO-8859-1 br_FR.ISO8859-1 br_FR.ISO-8859-15 br_FR.ISO8859-15 )],
119 brx_IN => [qw( brx_IN.UTF-8 )],
120 bs_BA => [qw( bs_BA.UTF-8 bs_BA.ISO-8859-2 bs_BA.ISO8859-2 )],
121 byn_ER => [qw( byn_ER.UTF-8 )],
122 ca_AD => [qw( ca_AD.UTF-8 ca_AD.ISO-8859-15 ca_AD.ISO8859-15 )],
123 ca_ES => [qw( ca_ES.UTF-8 ca_ES.ISO-8859-1 ca_ES.ISO8859-1 ca_ES.ISO-8859-15 ca_ES.ISO8859-15 )],
124 ca_FR => [qw( ca_FR.UTF-8 ca_FR.ISO-8859-15 ca_FR.ISO8859-15 )],
125 ca_IT => [qw( ca_IT.UTF-8 ca_IT.ISO-8859-15 ca_IT.ISO8859-15 )],
126 ce_RU => [qw( ce_RU.UTF-8 )],
127 ckb_IQ => [qw( ckb_IQ.UTF-8 )],
128 cmn_TW => [qw( cmn_TW.UTF-8 )],
129 crh_UA => [qw( crh_UA.UTF-8 )],
130 cs_CZ => [qw( cs_CZ.UTF-8 cs_CZ.ISO-8859-2 cs_CZ.ISO8859-2 )],
131 csb_PL => [qw( csb_PL.UTF-8 )],
132 cv_RU => [qw( cv_RU.UTF-8 )],
133 cy_GB => [qw( cy_GB.UTF-8 cy_GB.ISO-8859-14 cy_GB.ISO8859-14 )],
134 da_DK => [qw( da_DK.UTF-8 da_DK.ISO-8859-1 da_DK.ISO8859-1 )],
135 de_AT => [qw( de_AT.UTF-8 de_AT.ISO-8859-1 de_AT.ISO8859-1 de_AT.ISO-8859-15 de_AT.ISO8859-15 )],
136 de_BE => [qw( de_BE.UTF-8 de_BE.ISO-8859-1 de_BE.ISO8859-1 de_BE.ISO-8859-15 de_BE.ISO8859-15 )],
137 de_CH => [qw( de_CH.UTF-8 de_CH.ISO-8859-1 de_CH.ISO8859-1 )],
138 de_DE => [qw( de_DE.UTF-8 de_DE.ISO-8859-1 de_DE.ISO8859-1 de_DE.ISO-8859-15 de_DE.ISO8859-15 )],
139 de_LI => [qw( de_LI.UTF-8 )],
140 de_LU => [qw( de_LU.UTF-8 de_LU.ISO-8859-1 de_LU.ISO8859-1 de_LU.ISO-8859-15 de_LU.ISO8859-15 )],
141 doi_IN => [qw( doi_IN.UTF-8 )],
142 dv_MV => [qw( dv_MV.UTF-8 )],
143 dz_BT => [qw( dz_BT.UTF-8 )],
144 el_CY => [qw( el_CY.UTF-8 el_CY.ISO-8859-7 el_CY.ISO8859-7 )],
145 el_GR => [qw( el_GR.UTF-8 el_GR.ISO-8859-7 el_GR.ISO8859-7 )],
146 en_AG => [qw( en_AG.UTF-8 )],
147 en_AU => [qw( en_AU.UTF-8 en_AU.ISO-8859-1 en_AU.ISO8859-1 )],
148 en_BW => [qw( en_BW.UTF-8 en_BW.ISO-8859-1 en_BW.ISO8859-1 )],
149 en_CA => [qw( en_CA.UTF-8 en_CA.ISO-8859-1 en_CA.ISO8859-1 )],
150 en_DK => [qw( en_DK.UTF-8 en_DK.ISO-8859-15 en_DK.ISO8859-15 )],
151 en_GB => [qw( en_GB.UTF-8 en_GB.ISO-8859-1 en_GB.ISO8859-1 en_GB.ISO-8859-15 en_GB.ISO8859-15 )],
152 en_HK => [qw( en_HK.UTF-8 en_HK.ISO-8859-1 en_HK.ISO8859-1 )],
153 en_IE => [qw( en_IE.UTF-8 en_IE.ISO-8859-1 en_IE.ISO8859-1 en_IE.ISO-8859-15 en_IE.ISO8859-15 )],
154 en_IN => [qw( en_IN.UTF-8 )],
155 en_NG => [qw( en_NG.UTF-8 )],
156 en_NZ => [qw( en_NZ.UTF-8 en_NZ.ISO-8859-1 en_NZ.ISO8859-1 )],
157 en_PH => [qw( en_PH.UTF-8 en_PH.ISO-8859-1 en_PH.ISO8859-1 )],
158 en_SG => [qw( en_SG.UTF-8 en_SG.ISO-8859-1 en_SG.ISO8859-1 )],
159 en_US => [qw( en_US.UTF-8 en_US.ISO-8859-1 en_US.ISO8859-1 en_US.ISO-8859-15 en_US.ISO8859-15 )],
160 en_ZA => [qw( en_ZA.UTF-8 en_ZA.ISO-8859-1 en_ZA.ISO8859-1 )],
161 en_ZM => [qw( en_ZM.UTF-8 )],
162 en_ZW => [qw( en_ZW.UTF-8 en_ZW.ISO-8859-1 en_ZW.ISO8859-1 )],
163 eo => [qw( eo.UTF-8 eo.ISO-8859-3 eo.ISO8859-3 )],
164 eo_US => [qw( eo_US.UTF-8 )],
165 es_AR => [qw( es_AR.UTF-8 es_AR.ISO-8859-1 es_AR.ISO8859-1 )],
166 es_BO => [qw( es_BO.UTF-8 es_BO.ISO-8859-1 es_BO.ISO8859-1 )],
167 es_CL => [qw( es_CL.UTF-8 es_CL.ISO-8859-1 es_CL.ISO8859-1 )],
168 es_CO => [qw( es_CO.UTF-8 es_CO.ISO-8859-1 es_CO.ISO8859-1 )],
169 es_CR => [qw( es_CR.UTF-8 es_CR.ISO-8859-1 es_CR.ISO8859-1 )],
170 es_CU => [qw( es_CU.UTF-8 )],
171 es_DO => [qw( es_DO.UTF-8 es_DO.ISO-8859-1 es_DO.ISO8859-1 )],
172 es_EC => [qw( es_EC.UTF-8 es_EC.ISO-8859-1 es_EC.ISO8859-1 )],
173 es_ES => [qw( es_ES.UTF-8 es_ES.ISO-8859-1 es_ES.ISO8859-1 es_ES.ISO-8859-15 es_ES.ISO8859-15 )],
174 es_GT => [qw( es_GT.UTF-8 es_GT.ISO-8859-1 es_GT.ISO8859-1 )],
175 es_HN => [qw( es_HN.UTF-8 es_HN.ISO-8859-1 es_HN.ISO8859-1 )],
176 es_MX => [qw( es_MX.UTF-8 es_MX.ISO-8859-1 es_MX.ISO8859-1 )],
177 es_NI => [qw( es_NI.UTF-8 es_NI.ISO-8859-1 es_NI.ISO8859-1 )],
178 es_PA => [qw( es_PA.UTF-8 es_PA.ISO-8859-1 es_PA.ISO8859-1 )],
179 es_PE => [qw( es_PE.UTF-8 es_PE.ISO-8859-1 es_PE.ISO8859-1 )],
180 es_PR => [qw( es_PR.UTF-8 es_PR.ISO-8859-1 es_PR.ISO8859-1 )],
181 es_PY => [qw( es_PY.UTF-8 es_PY.ISO-8859-1 es_PY.ISO8859-1 )],
182 es_SV => [qw( es_SV.UTF-8 es_SV.ISO-8859-1 es_SV.ISO8859-1 )],
183 es_US => [qw( es_US.UTF-8 es_US.ISO-8859-1 es_US.ISO8859-1 )],
184 es_UY => [qw( es_UY.UTF-8 es_UY.ISO-8859-1 es_UY.ISO8859-1 )],
185 es_VE => [qw( es_VE.UTF-8 es_VE.ISO-8859-1 es_VE.ISO8859-1 )],
186 et_EE => [qw( et_EE.UTF-8 et_EE.ISO-8859-1 et_EE.ISO8859-1 et_EE.ISO-8859-15 et_EE.ISO8859-15 )],
187 eu_ES => [qw( eu_ES.UTF-8 eu_ES.ISO-8859-1 eu_ES.ISO8859-1 eu_ES.ISO-8859-15 eu_ES.ISO8859-15 )],
188 eu_FR => [qw( eu_FR.UTF-8 eu_FR.ISO-8859-1 eu_FR.ISO8859-1 eu_FR.ISO-8859-15 eu_FR.ISO8859-15 )],
189 fa_IR => [qw( fa_IR.UTF-8 )],
190 ff_SN => [qw( ff_SN.UTF-8 )],
191 fi_FI => [qw( fi_FI.UTF-8 fi_FI.ISO-8859-1 fi_FI.ISO8859-1 fi_FI.ISO-8859-15 fi_FI.ISO8859-15 )],
192 fil_PH => [qw( fil_PH.UTF-8 )],
193 fo_FO => [qw( fo_FO.UTF-8 fo_FO.ISO-8859-1 fo_FO.ISO8859-1 )],
194 fr_BE => [qw( fr_BE.UTF-8 fr_BE.ISO-8859-1 fr_BE.ISO8859-1 fr_BE.ISO-8859-15 fr_BE.ISO8859-15 )],
195 fr_CA => [qw( fr_CA.UTF-8 fr_CA.ISO-8859-1 fr_CA.ISO8859-1 )],
196 fr_CH => [qw( fr_CH.UTF-8 fr_CH.ISO-8859-1 fr_CH.ISO8859-1 )],
197 fr_FR => [qw( fr_FR.UTF-8 fr_FR.ISO-8859-1 fr_FR.ISO8859-1 fr_FR.ISO-8859-15 fr_FR.ISO8859-15 )],
198 fr_LU => [qw( fr_LU.UTF-8 fr_LU.ISO-8859-1 fr_LU.ISO8859-1 fr_LU.ISO-8859-15 fr_LU.ISO8859-15 )],
199 fur_IT => [qw( fur_IT.UTF-8 )],
200 fy_DE => [qw( fy_DE.UTF-8 )],
201 fy_NL => [qw( fy_NL.UTF-8 )],
202 ga_IE => [qw( ga_IE.UTF-8 ga_IE.ISO-8859-1 ga_IE.ISO8859-1 ga_IE.ISO-8859-15 ga_IE.ISO8859-15 )],
203 gd_GB => [qw( gd_GB.UTF-8 gd_GB.ISO-8859-15 gd_GB.ISO8859-15 )],
204 gez_ER => [qw( gez_ER.UTF-8 )],
205 gez_ET => [qw( gez_ET.UTF-8 )],
206 gl_ES => [qw( gl_ES.UTF-8 gl_ES.ISO-8859-1 gl_ES.ISO8859-1 gl_ES.ISO-8859-15 gl_ES.ISO8859-15 )],
207 gu_IN => [qw( gu_IN.UTF-8 )],
208 gv_GB => [qw( gv_GB.UTF-8 gv_GB.ISO-8859-1 gv_GB.ISO8859-1 )],
209 ha_NG => [qw( ha_NG.UTF-8 )],
210 hak_TW => [qw( hak_TW.UTF-8 )],
211 he_IL => [qw( he_IL.UTF-8 he_IL.ISO-8859-8 he_IL.ISO8859-8 )],
212 hi_IN => [qw( hi_IN.UTF-8 )],
213 hne_IN => [qw( hne_IN.UTF-8 )],
214 hr_HR => [qw( hr_HR.UTF-8 hr_HR.ISO-8859-2 hr_HR.ISO8859-2 )],
215 hsb_DE => [qw( hsb_DE.UTF-8 hsb_DE.ISO-8859-2 hsb_DE.ISO8859-2 )],
216 ht_HT => [qw( ht_HT.UTF-8 )],
217 hu_HU => [qw( hu_HU.UTF-8 hu_HU.ISO-8859-2 hu_HU.ISO8859-2 )],
218 hy_AM => [qw( hy_AM.UTF-8 hy_AM.ARMSCII-8 hy_AM.ARMSCII8 )],
219 ia_FR => [qw( ia_FR.UTF-8 )],
220 id_ID => [qw( id_ID.UTF-8 id_ID.ISO-8859-1 id_ID.ISO8859-1 )],
221 ig_NG => [qw( ig_NG.UTF-8 )],
222 ik_CA => [qw( ik_CA.UTF-8 )],
223 is_IS => [qw( is_IS.UTF-8 is_IS.ISO-8859-1 is_IS.ISO8859-1 )],
224 it_CH => [qw( it_CH.UTF-8 it_CH.ISO-8859-1 it_CH.ISO8859-1 )],
225 it_IT => [qw( it_IT.UTF-8 it_IT.ISO-8859-1 it_IT.ISO8859-1 it_IT.ISO-8859-15 it_IT.ISO8859-15 )],
226 iu_CA => [qw( iu_CA.UTF-8 )],
227 iw_IL => [qw( iw_IL.UTF-8 iw_IL.ISO-8859-8 iw_IL.ISO8859-8 )],
228 ja_JP => [qw( ja_JP.UTF-8 ja_JP.EUC-JP ja_JP.EUCJP )],
229 ka_GE => [qw( ka_GE.UTF-8 ka_GE.GEORGIAN-PS ka_GE.GEORGIANPS )],
230 kk_KZ => [qw( kk_KZ.UTF-8 kk_KZ.PT154 kk_KZ.RK1048 )],
231 kl_GL => [qw( kl_GL.UTF-8 kl_GL.ISO-8859-1 kl_GL.ISO8859-1 )],
232 km_KH => [qw( km_KH.UTF-8 )],
233 kn_IN => [qw( kn_IN.UTF-8 )],
234 ko_KR => [qw( ko_KR.UTF-8 ko_KR.EUC-KR ko_KR.EUCKR )],
235 kok_IN => [qw( kok_IN.UTF-8 )],
236 ks_IN => [qw( ks_IN.UTF-8 )],
237 ku_TR => [qw( ku_TR.UTF-8 ku_TR.ISO-8859-9 ku_TR.ISO8859-9 )],
238 kw_GB => [qw( kw_GB.UTF-8 kw_GB.ISO-8859-1 kw_GB.ISO8859-1 )],
239 ky_KG => [qw( ky_KG.UTF-8 )],
240 lb_LU => [qw( lb_LU.UTF-8 )],
241 lg_UG => [qw( lg_UG.UTF-8 lg_UG.ISO-8859-10 lg_UG.ISO8859-10 )],
242 li_BE => [qw( li_BE.UTF-8 )],
243 li_NL => [qw( li_NL.UTF-8 )],
244 lij_IT => [qw( lij_IT.UTF-8 )],
245 ln_CD => [qw( ln_CD.UTF-8 )],
246 lo_LA => [qw( lo_LA.UTF-8 )],
247 lt_LT => [qw( lt_LT.UTF-8 lt_LT.ISO-8859-13 lt_LT.ISO8859-13 )],
248 lv_LV => [qw( lv_LV.UTF-8 lv_LV.ISO-8859-13 lv_LV.ISO8859-13 )],
249 lzh_TW => [qw( lzh_TW.UTF-8 )],
250 mag_IN => [qw( mag_IN.UTF-8 )],
251 mai_IN => [qw( mai_IN.UTF-8 )],
252 mg_MG => [qw( mg_MG.UTF-8 mg_MG.ISO-8859-15 mg_MG.ISO8859-15 )],
253 mhr_RU => [qw( mhr_RU.UTF-8 )],
254 mi_NZ => [qw( mi_NZ.UTF-8 mi_NZ.ISO-8859-13 mi_NZ.ISO8859-13 )],
255 mk_MK => [qw( mk_MK.UTF-8 mk_MK.ISO-8859-5 mk_MK.ISO8859-5 )],
256 ml_IN => [qw( ml_IN.UTF-8 )],
257 mn_MN => [qw( mn_MN.UTF-8 )],
258 mni_IN => [qw( mni_IN.UTF-8 )],
259 mr_IN => [qw( mr_IN.UTF-8 )],
260 ms_MY => [qw( ms_MY.UTF-8 ms_MY.ISO-8859-1 ms_MY.ISO8859-1 )],
261 mt_MT => [qw( mt_MT.UTF-8 mt_MT.ISO-8859-3 mt_MT.ISO8859-3 )],
262 my_MM => [qw( my_MM.UTF-8 )],
263 nan_TW => [qw( nan_TW.UTF-8 )],
264 nb_NO => [qw( nb_NO.UTF-8 nb_NO.ISO-8859-1 nb_NO.ISO8859-1 )],
265 nds_DE => [qw( nds_DE.UTF-8 )],
266 nds_NL => [qw( nds_NL.UTF-8 )],
267 ne_NP => [qw( ne_NP.UTF-8 )],
268 nhn_MX => [qw( nhn_MX.UTF-8 )],
269 niu_NU => [qw( niu_NU.UTF-8 )],
270 niu_NZ => [qw( niu_NZ.UTF-8 )],
271 nl_AW => [qw( nl_AW.UTF-8 )],
272 nl_BE => [qw( nl_BE.UTF-8 nl_BE.ISO-8859-1 nl_BE.ISO8859-1 nl_BE.ISO-8859-15 nl_BE.ISO8859-15 )],
273 nl_NL => [qw( nl_NL.UTF-8 nl_NL.ISO-8859-1 nl_NL.ISO8859-1 nl_NL.ISO-8859-15 nl_NL.ISO8859-15 )],
274 nn_NO => [qw( nn_NO.UTF-8 nn_NO.ISO-8859-1 nn_NO.ISO8859-1 )],
275 nr_ZA => [qw( nr_ZA.UTF-8 )],
276 nso_ZA => [qw( nso_ZA.UTF-8 )],
277 oc_FR => [qw( oc_FR.UTF-8 oc_FR.ISO-8859-1 oc_FR.ISO8859-1 )],
278 om_ET => [qw( om_ET.UTF-8 )],
279 om_KE => [qw( om_KE.UTF-8 om_KE.ISO-8859-1 om_KE.ISO8859-1 )],
280 or_IN => [qw( or_IN.UTF-8 )],
281 os_RU => [qw( os_RU.UTF-8 )],
282 pa_IN => [qw( pa_IN.UTF-8 )],
283 pa_PK => [qw( pa_PK.UTF-8 )],
284 pap_AN => [qw( pap_AN.UTF-8 )],
285 pap_AW => [qw( pap_AW.UTF-8 )],
286 pap_CW => [qw( pap_CW.UTF-8 )],
287 pl_PL => [qw( pl_PL.UTF-8 pl_PL.ISO-8859-2 pl_PL.ISO8859-2 )],
288 ps_AF => [qw( ps_AF.UTF-8 )],
289 pt_BR => [qw( pt_BR.UTF-8 pt_BR.ISO-8859-1 pt_BR.ISO8859-1 )],
290 pt_PT => [qw( pt_PT.UTF-8 pt_PT.ISO-8859-1 pt_PT.ISO8859-1 pt_PT.ISO-8859-15 pt_PT.ISO8859-15 )],
291 quz_PE => [qw( quz_PE.UTF-8 )],
292 raj_IN => [qw( raj_IN.UTF-8 )],
293 ro_RO => [qw( ro_RO.UTF-8 ro_RO.ISO-8859-2 ro_RO.ISO8859-2 )],
294 ru_RU => [qw( ru_RU.UTF-8 ru_RU.KOI8-R ru_RU.KOI8R ru_RU.ISO-8859-5 ru_RU.ISO8859-5 ru_RU.CP1251 )],
295 ru_UA => [qw( ru_UA.UTF-8 ru_UA.KOI8-U ru_UA.KOI8U )],
296 rw_RW => [qw( rw_RW.UTF-8 )],
297 sa_IN => [qw( sa_IN.UTF-8 )],
298 sat_IN => [qw( sat_IN.UTF-8 )],
299 sc_IT => [qw( sc_IT.UTF-8 )],
300 sd_IN => [qw( sd_IN.UTF-8 )],
301 sd_PK => [qw( sd_PK.UTF-8 )],
302 se_NO => [qw( se_NO.UTF-8 )],
303 shs_CA => [qw( shs_CA.UTF-8 )],
304 si_LK => [qw( si_LK.UTF-8 )],
305 sid_ET => [qw( sid_ET.UTF-8 )],
306 sk_SK => [qw( sk_SK.UTF-8 sk_SK.ISO-8859-2 sk_SK.ISO8859-2 )],
307 sl_SI => [qw( sl_SI.UTF-8 sl_SI.ISO-8859-2 sl_SI.ISO8859-2 )],
308 so_DJ => [qw( so_DJ.UTF-8 so_DJ.ISO-8859-1 so_DJ.ISO8859-1 )],
309 so_ET => [qw( so_ET.UTF-8 )],
310 so_KE => [qw( so_KE.UTF-8 so_KE.ISO-8859-1 so_KE.ISO8859-1 )],
311 so_SO => [qw( so_SO.UTF-8 so_SO.ISO-8859-1 so_SO.ISO8859-1 )],
312 sq_AL => [qw( sq_AL.UTF-8 sq_AL.ISO-8859-1 sq_AL.ISO8859-1 )],
313 sq_MK => [qw( sq_MK.UTF-8 )],
314 sr_ME => [qw( sr_ME.UTF-8 )],
315 sr_RS => [qw( sr_RS.UTF-8 )],
316 ss_ZA => [qw( ss_ZA.UTF-8 )],
317 st_ZA => [qw( st_ZA.UTF-8 st_ZA.ISO-8859-1 st_ZA.ISO8859-1 )],
318 sv_FI => [qw( sv_FI.UTF-8 sv_FI.ISO-8859-1 sv_FI.ISO8859-1 sv_FI.ISO-8859-15 sv_FI.ISO8859-15 )],
319 sv_SE => [qw( sv_SE.UTF-8 sv_SE.ISO-8859-1 sv_SE.ISO8859-1 sv_SE.ISO-8859-15 sv_SE.ISO8859-15 )],
320 sw_KE => [qw( sw_KE.UTF-8 )],
321 sw_TZ => [qw( sw_TZ.UTF-8 )],
322 szl_PL => [qw( szl_PL.UTF-8 )],
323 ta_IN => [qw( ta_IN.UTF-8 )],
324 ta_LK => [qw( ta_LK.UTF-8 )],
325 tcy_IN => [qw( tcy_IN.UTF-8 )],
326 te_IN => [qw( te_IN.UTF-8 )],
327 tg_TJ => [qw( tg_TJ.UTF-8 tg_TJ.KOI8-T tg_TJ.KOI8T )],
328 th_TH => [qw( th_TH.UTF-8 th_TH.TIS-620 th_TH.TIS620 )],
329 the_NP => [qw( the_NP.UTF-8 )],
330 ti_ER => [qw( ti_ER.UTF-8 )],
331 ti_ET => [qw( ti_ET.UTF-8 )],
332 tig_ER => [qw( tig_ER.UTF-8 )],
333 tk_TM => [qw( tk_TM.UTF-8 )],
334 tl_PH => [qw( tl_PH.UTF-8 tl_PH.ISO-8859-1 tl_PH.ISO8859-1 )],
335 tn_ZA => [qw( tn_ZA.UTF-8 )],
336 tr_CY => [qw( tr_CY.UTF-8 tr_CY.ISO-8859-9 tr_CY.ISO8859-9 )],
337 tr_TR => [qw( tr_TR.UTF-8 tr_TR.ISO-8859-9 tr_TR.ISO8859-9 )],
338 ts_ZA => [qw( ts_ZA.UTF-8 )],
339 tt_RU => [qw( tt_RU.UTF-8 )],
340 ug_CN => [qw( ug_CN.UTF-8 )],
341 uk_UA => [qw( uk_UA.UTF-8 uk_UA.KOI8-U uk_UA.KOI8U )],
342 unm_US => [qw( unm_US.UTF-8 )],
343 ur_IN => [qw( ur_IN.UTF-8 )],
344 ur_PK => [qw( ur_PK.UTF-8 )],
345 uz_UZ => [qw( uz_UZ.UTF-8 uz_UZ.ISO-8859-1 uz_UZ.ISO8859-1 )],
346 ve_ZA => [qw( ve_ZA.UTF-8 )],
347 vi_VN => [qw( vi_VN.UTF-8 )],
348 wa_BE => [qw( wa_BE.UTF-8 wa_BE.ISO-8859-1 wa_BE.ISO8859-1 wa_BE.ISO-8859-15 wa_BE.ISO8859-15 )],
349 wae_CH => [qw( wae_CH.UTF-8 )],
350 wal_ET => [qw( wal_ET.UTF-8 )],
351 wo_SN => [qw( wo_SN.UTF-8 )],
352 xh_ZA => [qw( xh_ZA.UTF-8 xh_ZA.ISO-8859-1 xh_ZA.ISO8859-1 )],
353 yi_US => [qw( yi_US.UTF-8 yi_US.CP1255 )],
354 yo_NG => [qw( yo_NG.UTF-8 )],
355 yue_HK => [qw( yue_HK.UTF-8 )],
356 zh_CN => [qw( zh_CN.UTF-8 zh_CN.GB18030 zh_CN.GBK zh_CN.GB2312 )],
357 zh_HK => [qw( zh_HK.UTF-8 zh_HK.BIG5-HKSCS zh_HK.BIG5HKSCS )],
358 zh_SG => [qw( zh_SG.UTF-8 zh_SG.GBK zh_SG.GB2312 )],
359 zh_TW => [qw( zh_TW.UTF-8 zh_TW.EUC-TW zh_TW.EUCTW zh_TW.BIG5 )],
360 zu_ZA => [qw( zu_ZA.UTF-8 zu_ZA.ISO-8859-1 zu_ZA.ISO8859-1 )],
361 };
362  
363 # NOTE: $DEFAULT
364 2 $DEFAULT =
365 {
366 # The local currency symbol.
367 currency_symbol => '€',
368 # The decimal point character, except for currency values, cannot be an empty string
369 decimal_point => '.',
370 # The number of digits after the decimal point in the local style for currency values.
371 frac_digits => 2,
372 # The sizes of the groups of digits, except for currency values. unpack( "C*", $grouping ) will give the number
373 grouping => (CORE::chr(3) x 2),
374 # The standardized international currency symbol.
375 int_curr_symbol => '€',
376 # The number of digits after the decimal point in an international-style currency value.
377 int_frac_digits => 2,
378 # Same as n_cs_precedes, but for internationally formatted monetary quantities.
379 int_n_cs_precedes => '',
380 # Same as n_sep_by_space, but for internationally formatted monetary quantities.
381 int_n_sep_by_space => '',
382 # Same as n_sign_posn, but for internationally formatted monetary quantities.
383 int_n_sign_posn => 1,
384 # Same as p_cs_precedes, but for internationally formatted monetary quantities.
385 int_p_cs_precedes => 1,
386 # Same as p_sep_by_space, but for internationally formatted monetary quantities.
387 int_p_sep_by_space => 0,
388 # Same as p_sign_posn, but for internationally formatted monetary quantities.
389 int_p_sign_posn => 1,
390 # The decimal point character for currency values.
391 mon_decimal_point => '.',
392 # Like grouping but for currency values.
393 mon_grouping => (CORE::chr(3) x 2),
394 # The separator for digit groups in currency values.
395 mon_thousands_sep => ',',
396 # Like p_cs_precedes but for negative values.
397 n_cs_precedes => 1,
398 # Like p_sep_by_space but for negative values.
399 n_sep_by_space => 0,
400 # Like p_sign_posn but for negative currency values.
401 n_sign_posn => 1,
402 # The character used to denote negative currency values, usually a minus sign.
403 negative_sign => '-',
404 # 1 if the currency symbol precedes the currency value for nonnegative values, 0 if it follows.
405 p_cs_precedes => 1,
406 # 1 if a space is inserted between the currency symbol and the currency value for nonnegative values, 0 otherwise.
407 p_sep_by_space => 0,
408 # The location of the positive_sign with respect to a nonnegative quantity and the currency_symbol, coded as follows:
409 # 0 Parentheses around the entire string.
410 # 1 Before the string.
411 # 2 After the string.
412 # 3 Just before currency_symbol.
413 # 4 Just after currency_symbol.
414 p_sign_posn => 1,
415 # The character used to denote nonnegative currency values, usually the empty string.
416 positive_sign => '',
417 # The separator between groups of digits before the decimal point, except for currency values
418 thousands_sep => ',',
419 };
420  
421 # NOTE: $map_flexible
422 2 my $map_flexible =
423 {
424 decimal => [qw( decimal_point mon_decimal_point )],
425 grouping => [qw( grouping mon_grouping )],
426 mon_decimal => [qw( mon_decimal_point decimal_point )],
427 mon_grouping => [qw( mon_grouping grouping )],
428 mon_thousand => [qw( mon_thousands_sep thousands_sep )],
429 position_neg => [qw( n_sign_posn int_n_sign_posn )],
430 position_pos => [qw( p_sign_posn int_p_sign_posn )],
431 precede => [qw( p_cs_precedes int_p_cs_precedes )],
432 precede_neg => [qw( n_cs_precedes int_n_cs_precedes )],
433 precision => [qw( frac_digits int_frac_digits )],
434 sign_neg => [qw( negative_sign )],
435 sign_pos => [qw( positive_sign )],
436 space_pos => [qw( p_sep_by_space int_p_sep_by_space )],
437 space_neg => [qw( n_sep_by_space int_n_sep_by_space )],
438 symbol => [qw( currency_symbol int_curr_symbol )],
439 thousand => [qw( thousands_sep mon_thousands_sep )],
440 };
441  
442 # NOTE: $map_posix_strict
443 2 my $map_posix_strict =
444 {
445 decimal => [qw( decimal_point )],
446 grouping => [qw( grouping )],
447 mon_decimal => [qw( mon_decimal_point )],
448 mon_grouping => [qw( mon_grouping )],
449 mon_thousand => [qw( mon_thousands_sep )],
450 position_neg => [qw( n_sign_posn int_n_sign_posn )],
451 position_pos => [qw( p_sign_posn int_p_sign_posn )],
452 precede => [qw( p_cs_precedes int_p_cs_precedes )],
453 precede_neg => [qw( n_cs_precedes int_n_cs_precedes )],
454 precision => [qw( frac_digits int_frac_digits )],
455 sign_neg => [qw( negative_sign )],
456 sign_pos => [qw( positive_sign )],
457 space_pos => [qw( p_sep_by_space int_p_sep_by_space )],
458 space_neg => [qw( n_sep_by_space int_n_sep_by_space )],
459 symbol => [qw( currency_symbol int_curr_symbol )],
460 thousand => [qw( thousands_sep )],
461 };
462  
463 2 my $map = $map_flexible;
464  
465 # This serves 2 purposes:
466 # 1) to silence warnings issued from Number::Format when it uses an empty string when evaluating a number, e.g. '' == 1
467 # 2) to ensure that blank numerical values are not interpreted to anything else than equivalent of empty
468 # For example, an empty frac_digits will default to 2 in Number::Format even if the user does not want any. Of course, said user could also have set it to 0
469 # So here we use this hash reference of numeric properties to ensure the option parameters are set to a numeric value (0) when they are empty.
470 # NOTE: $numerics
471 2 my $numerics =
472 {
473 grouping => 0,
474 frac_digits => 0,
475 int_frac_digits => 0,
476 int_n_cs_precedes => 0,
477 int_p_cs_precedes => 0,
478 int_n_sep_by_space => 0,
479 int_p_sep_by_space => 0,
480 int_n_sign_posn => 1,
481 int_p_sign_posn => 1,
482 mon_grouping => 0,
483 n_cs_precedes => 0,
484 n_sep_by_space => 0,
485 n_sign_posn => 1,
486 p_cs_precedes => 0,
487 p_sep_by_space => 0,
488 # Position of positive sign. 1 = before (0 = parentheses)
489 p_sign_posn => 1,
490 };
491  
492 sub init
493 15 ▶{
Subroutine init: called CC=31 SCAR=44.0
Pod documented
494 15 my $self = shift( @_ );
495 15 ▶ return( $self->error( "No number was provided." ) ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 0 15 15
496 15 my $num = shift( @_ );
497 {
498 2 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
499 15 ▶ if( isinf( $num ) || isnan( $num ) )
Branch: 1 branch
BranchTrueFalseTotal
if (isinf($num) or isnan($num)) 0 15 15
Condition33%1/3
isinf($num) or isnan($num)
l!l&&r!l&&!r
0015
MC/DC0%0/2
isinf($num) or isnan($num)
isinf($num) isnan($num)
Truth table33%1/3
A or B
A= isinf($num)B= isnan($num)
ABresult
1X1
011
000
500 {
501 0 return( $self->error( "The number provided is an Infinite or NaN, and cannot be formatted." ) );
502 }
503 }
504 15 my $opts = $self->_get_args_as_hash( @_ );
505 15 ▶ $self->debug( CORE::delete( $opts->{debug} ) ) if( CORE::exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"debug"} 1 14 15
506 2 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
507 # NOTE: we set the default instance value
508 15 my @k = keys( %$map );
509 15 @$self{ @k } = ( '' ) x scalar( @k );
510 15 $self->{locale} = '';
511 15 $self->{posix_strict} = 1;
512 15 $self->{default} = $DEFAULT;
513 15 $self->{decimal_fill} = 0;
514 15 $self->{encoding} = 'utf-8';
515 15 $self->{neg_format} = '-x';
516 15 $self->{kilo_suffix} = 'K';
517 15 $self->{mega_suffix} = 'M';
518 15 $self->{giga_suffix} = 'G';
519 15 $self->{kibi_suffix} = 'KiB';
520 15 $self->{mebi_suffix} = 'MiB';
521 15 $self->{gibi_suffix} = 'GiB';
522  
523 # NOTE: we prepare the instance data based on:
524 # 1) the POSIX lconv data for the specified locale, if any.
525 # 2) the POSIX lconv data for the currently used system locale
526 # Then, those basic values can be overriden by the options provided now upon instantiation
527 15 my $default = $self->default;
528 15 my $curr_locale = POSIX::setlocale( &POSIX::LC_ALL );
529 15 ▶ if( defined( $curr_locale ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $curr_locale and length $curr_locale) 15 0 15
Condition33%1/3
defined $curr_locale and length $curr_locale
!ll&&!rl&&r
0015
MC/DC0%0/2
defined $curr_locale and length $curr_locale
defined $curr_locale length $curr_locale
Truth table33%1/3
A and B
A= defined $curr_localeB= length $curr_locale
ABresult
0X0
100
111
530 CORE::length( $curr_locale ) )
531 {
532 15 ▶ if( CORE::index( $curr_locale, ';' ) != -1 )
Branch: 2 branches
BranchTrueFalseTotal
if (index($curr_locale, ';') != -1) { } 0 15 15
elsif (index($curr_locale, '/') != -1) { } 0 15 15
533 {
534 # GNU/Linux "LC_NAME=value;LC_NAME=value" composite format.
535 0 my @parts = CORE::split( /;/, $curr_locale );
536 0 my $elems = {};
537 0 for( @parts )
538 {
539 0 my( $n, $v ) = CORE::split( /=/, $_, 2 );
540 0 $elems->{ $n } = $v;
541 }
542 0 ▶ $curr_locale = $elems->{LC_NUMERIC} || $elems->{LC_MESSAGES} || $elems->{LC_MONETARY};
Condition0%0/6
$elems->{'LC_NUMERIC'} || $elems->{'LC_MESSAGES'} || $elems->{'LC_MONETARY'}
l!l&&r!l&&!r
000
$elems->{"LC_NUMERIC"} or $elems->{"LC_MESSAGES"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$elems->{'LC_NUMERIC'} || $elems->{'LC_MESSAGES'} || $elems->{'LC_MONETARY'}
$elems->{"LC_NUMERIC"} $elems->{"LC_MESSAGES"} $elems->{'LC_MONETARY'}
Truth table0%0/4
A or B || C
A= $elems->{"LC_NUMERIC"}B= $elems->{"LC_MESSAGES"}C= $elems->{'LC_MONETARY'}
ABCresult
1XX1
01X1
0011
0000
543 }
544 # OpenBSD/FreeBSD "C/fr_FR.UTF-8/C/C/C/C"
545 # However the order LC_CTYPE/LC_COLLATE/LC_TIME/LC_NUMERIC/LC_MONETARY/LC_MESSAGES is not guaranteed across platforms.
546 elsif( CORE::index( $curr_locale, '/' ) != -1 )
547 {
548 # BSD "val1/val2/..." composite format: the string does not carry category names,
549 # so we query LC_NUMERIC directly — it is the category that drives localeconv()
550 # for numeric formatting.
551 0 ▶ $curr_locale = POSIX::setlocale( &POSIX::LC_NUMERIC ) // $curr_locale;
Condition0%0/3
POSIX::setlocale(&POSIX::LC_NUMERIC) // $curr_locale
l!l&&r!l&&!r
000
MC/DC0%0/2
POSIX::setlocale(&POSIX::LC_NUMERIC) // $curr_locale
POSIX::setlocale(&POSIX::LC_NUMERIC) $curr_locale
Truth table0%0/3
A // B
A= POSIX::setlocale(&POSIX::LC_NUMERIC)B= $curr_locale
ABresult
1X1
011
000
552 }
553 }
554 15 my $already_propagated = 0;
555 15 ▶ if( $opts->{locale} )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'locale'}) { } 0 15 15
elsif ($curr_locale and my $lconv = POSIX::localeconv()) { } 15 0 15
556 {
557 0 ▶ $self->set_locale( $opts->{locale} ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->set_locale($opts->{"locale"}) or return $self->pass_error 0 0 0
558 0 $already_propagated++;
559 }
560 ▶ elsif( $curr_locale && ( my $lconv = POSIX::localeconv() ) )
Condition33%1/3
$curr_locale and my $lconv = POSIX::localeconv()
!ll&&!rl&&r
0015
MC/DC0%0/2
$curr_locale and my $lconv = POSIX::localeconv()
$curr_locale my $lconv = POSIX::localeconv()
Truth table33%1/3
A and B
A= $curr_localeB= my $lconv = POSIX::localeconv()
ABresult
0X0
100
111
561 {
562 # Encode and I18N::Langinfo are both core modules since before perl 5.26.1, which is our minimum requirement
563 15 ▶ $self->_load_class( 'Encode' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Encode") or return $self->pass_error 15 0 15
564 15 ▶ $self->_load_class( 'I18N::Langinfo' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("I18N::Langinfo") or return $self->pass_error 15 0 15
565 my $encoding = eval
566 15 ▶ {
Condition50%1/2
eval { do { &Encode::resolve_alias(scalar I18N::Langinfo::langinfo(I18N::Langinfo::CODESET())) } } || 'utf-8'
l!l
150
MC/DC0%0/1
eval { do { &Encode::resolve_alias(scalar I18N::Langinfo::langinfo(I18N::Langinfo::CODESET())) } } || 'utf-8'
eval { do { &Encode::resolve_alias(scalar I18N::Langinfo::langinfo(I18N::Langinfo::CODESET())) } }
Truth table50%1/2
A
A= eval { do { &Encode::resolve_alias(scalar I18N::Langinfo::langinfo(I18N::Langinfo::CODESET())) } }
Aresult
11
00
567 15 Encode::resolve_alias( I18N::Langinfo::langinfo( I18N::Langinfo::CODESET() ) );
568 } || 'utf-8';
569 15 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 15 15
570 {
571 0 ▶ warn( "Error trying to resolve alias for POSIX::localeconv codeset: $@" ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 0 0 0
572 }
573 15 $self->encoding( $encoding );
574 15 ▶ if( scalar( keys( %$lconv ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$lconv) 15 0 15
575 {
576 15 $lconv->{grouping} = $self->_normalise_lconv_grouping( $lconv->{grouping} );
577 15 $lconv->{mon_grouping} = $self->_normalise_lconv_grouping( $lconv->{mon_grouping} );
578 15 $default = $lconv;
579 15 ▶ if( my $decoded = $self->decode_lconv( $default ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $decoded = $self->decode_lconv($default)) 15 0 15
580 {
581 15 $default = $decoded;
582 }
583 }
584 # To simulate running on Windows
585 # my $fail = [qw(
586 # frac_digits
587 # int_frac_digits
588 # n_cs_precedes
589 # n_sep_by_space
590 # n_sign_posn
591 # p_cs_precedes
592 # p_sep_by_space
593 # p_sign_posn
594 # )];
595 # @$lconv{ @$fail } = ( -1 ) x scalar( @$fail );
596 15 $self->{locale} = $curr_locale;
597 }
598  
599 15 ▶ unless( $already_propagated )
Branch: 1 branch
BranchTrueFalseTotal
unless ($already_propagated) 15 0 15
600 {
601 15 ▶ $self->_propagate_values( $default ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_propagate_values($default) or return $self->pass_error 15 0 15
602 }
603  
604 # Convert Japanese double bytes numbers to regular digits.
605 15 $num =~ tr/[\x{FF10}-\x{FF19}]+ー/[0-9]+-/;
606 15 ▶ if( $num !~ /^$NUMBER_RE$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (not $num =~ /^$NUMBER_RE$/) { } 1 14 15
607 {
608 1 my $clean = $self->unformat( $num );
609 1 ▶ return( $self->pass_error ) if( !defined( $clean ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $clean and $self->error 1 0 1
Condition33%1/3
not defined $clean and $self->error
!ll&&!rl&&r
001
MC/DC0%0/2
not defined $clean and $self->error
not defined $clean $self->error
Truth table33%1/3
not(A) and B
A= not defined $cleanB= $self->error
ABresult
0X0
100
111
610 0 $self->{_number} = $clean;
611 }
612 else
613 {
614 14 $self->{_number} = $num;
615 }
616 14 ▶ return( $self->error( "Invalid number: $num (", overload::StrVal( $num ), ")" ) ) if( !defined( $self->{_number} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_number"} 0 14 14
617  
618 14 $self->{_init_strict_use_sub} = 1;
619 14 ▶ $self->SUPER::init( %$opts ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(%$opts) or return $self->pass_error 14 0 14
620 14 $self->{_original} = $num;
621 14 $self->{_fields} = [qw(
622 locale posix_strict decimal_fill encoding neg_format kilo_suffix mega_suffix
623 giga_suffix kibi_suffix mebi_suffix gibi_suffix _number
624 )];
625 14 return( $self );
626 }
627  
628 # This class does not convert to an HASH, but the TO_JSON method will convert to a string
629 0 ▶sub as_hash { return( $_[0] ); }
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
630  
631 0 ▶sub as_string { return( shift->{_number} ) }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
632  
633 sub clone
634 66 ▶{
Subroutine clone: called CC=10 SCAR=29.7
Pod documented
635 66 my $self = shift( @_ );
636 66 ▶ return( $self->error( 'clone() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 66 66
637 66 my $new;
638 # Called as a class function
639 66 ▶ if( !$self->_is_object( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_is_object($self)) { } 0 66 66
640 {
641 0 ▶ my $num = shift( @_ ) // 0;
Condition0%0/2
shift @_ // 0
l!l
00
MC/DC0%0/1
shift @_ // 0
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
642 0 $new = $self->new( $num );
643 0 ▶ return( $self->pass_error ) if( !defined( $new ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 0 0
644 }
645 else
646 {
647 66 ▶ my $num = @_ ? shift( @_ ) : $self->{_number};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 66 0 66
648 66 ▶ my $actual_num = $self->_is_a( $num => 'Module::Generic::Number' ) ? $num->{_number} : $num;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($num, 'Module::Generic::Number') ? : 0 66 66
649 66 ▶ if( isinf( $actual_num ) || isnan( $actual_num ) )
Branch: 1 branch
BranchTrueFalseTotal
if (isinf($actual_num) or isnan($actual_num)) 0 66 66
Condition33%1/3
isinf($actual_num) or isnan($actual_num)
l!l&&r!l&&!r
0066
MC/DC0%0/2
isinf($actual_num) or isnan($actual_num)
isinf($actual_num) isnan($actual_num)
Truth table33%1/3
A or B
A= isinf($actual_num)B= isnan($actual_num)
ABresult
1X1
011
000
650 {
651 0 return( $self->error( "The number provided is an Infinite or NaN, and cannot be formatted." ) );
652 }
653 66 $new = $self->SUPER::clone;
654 66 ▶ return( $self->pass_error ) if( !defined( $new ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 66 66
655 66 $new->{_number} = $actual_num;
656 66 $new->clear_error;
657 }
658 66 return( $new );
659 }
660  
661 10 ▶sub currency { return( shift->_set_get_prop( 'symbol', @_ ) ); }
Subroutine currency: called CC=1 SCAR=0.0
Pod documented
662  
663 40 ▶sub decimal { return( shift->_set_get_prop( 'decimal', @_ ) ); }
Subroutine decimal: called CC=1 SCAR=0.0
Pod documented
664  
665 16 ▶sub decimal_fill { return( shift->_set_get_prop( 'decimal_fill', @_ ) ); }
Subroutine decimal_fill: called CC=1 SCAR=0.0
Pod documented
666  
667 sub decode_lconv
668 16 ▶{
Subroutine decode_lconv: called CC=10 SCAR=24.4
Pod documented
669 16 my $self = shift( @_ );
670 16 my $ref = shift( @_ );
671 16 ▶ return( $self->error( "Value provided is not an hash reference." ) ) if( !$self->_is_hash( $ref => 'strict' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_hash($ref, "strict") 0 16 16
672 16 ▶ my $encoding = $self->encoding || 'utf-8';
Condition50%1/2
$self->encoding || 'utf-8'
l!l
160
MC/DC0%0/1
$self->encoding || 'utf-8'
$self->encoding
Truth table50%1/2
A
A= $self->encoding
Aresult
11
00
673  
674 16 foreach my $prop ( keys( %$ref ) )
675 {
676 384 ▶ next if( $prop eq 'grouping' || $prop eq 'mon_grouping' );
Branch: 1 branch
BranchTrueFalseTotal
if $prop eq "grouping" or $prop eq "mon_grouping" 32 352 384
Condition100%3/3
$prop eq "grouping" or $prop eq "mon_grouping"
l!l&&r!l&&!r
1616352
MC/DC100%2/2
$prop eq "grouping" or $prop eq "mon_grouping"
$prop eq "grouping" $prop eq "mon_grouping"
Truth table100%3/3
A or B
A= $prop eq "grouping"B= $prop eq "mon_grouping"
ABresult
1X1
011
000
677 352 my $v = $ref->{ $prop };
678 352 ▶ next if( utf8::is_utf8( $v ) || $self->_is_empty( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($v) or $self->_is_empty($v) 112 240 352
Condition66%2/3
utf8::is_utf8($v) or $self->_is_empty($v)
l!l&&r!l&&!r
0112240
MC/DC50%1/2
utf8::is_utf8($v) or $self->_is_empty($v)
utf8::is_utf8($v) $self->_is_empty($v)
Truth table66%2/3
A or B
A= utf8::is_utf8($v)B= $self->_is_empty($v)
ABresult
1X1
011
000
679 my $rv = eval
680 240 {
681 240 return( Encode::decode(
682 $encoding,
683 $v,
684 Encode::FB_CROAK()
685 ) );
686 };
687 240 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 240 240
688 {
689 0 ▶ warn( "Error trying to decode POSIX::localeconv property ${prop} and language $self->{locale}: $@" ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 0 0 0
690 0 next;
691 }
692 240 $ref->{ $prop } = $rv;
693 }
694 16 return( $ref );
695 };
696  
697 # sub default { return( shift->_set_get_hash_as_mix_object( 'default', @_ ) ); }
698 15 ▶sub default { return( shift->_set_get_hash( 'default', @_ ) ); }
Subroutine default: called CC=1 SCAR=0.0
Pod documented
699  
700 31 ▶sub encoding { return( shift->_set_get_scalar( 'encoding', @_ ) ); }
Subroutine encoding: called CC=1 SCAR=0.0
Pod documented
701  
702 sub format
703 16 ▶{
Subroutine format: called CC=32 SCAR=38.5
Pod documented
704 16 my $self = shift( @_ );
705 16 my $precision;
706 16 ▶ $precision = shift( @_ ) if( scalar( @_ ) && $_[0] =~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ and $_[0] =~ /^\d+$/ 5 11 16
Condition100%3/3
scalar @_ and $_[0] =~ /^\d+$/
!ll&&!rl&&r
745
MC/DC100%2/2
scalar @_ and $_[0] =~ /^\d+$/
scalar @_ $_[0] =~ /^\d+$/
Truth table100%3/3
A and B
A= scalar @_B= $_[0] =~ /^\d+$/
ABresult
0X0
100
111
707 16 my $opts = $self->_get_args_as_hash( @_ );
708 16 ▶ return( $self->error( 'format() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 16 16
709 2 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
710 16 my $number = $self->{_number};
711 # If value provided was undefined, we leave it undefined, otherwise we would be at risk of returning 0, and 0 is very different from undefined
712 16 ▶ return( $number ) if( !defined( $number ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 16 16
713 16 ▶ $precision //= $opts->{precision} // $self->precision;
Condition66%4/6
$precision //= $opts->{"precision"} // $self->precision
l!l&&r!l&&!r
5110
$opts->{"precision"} // $self->precision
l!l&&r!l&&!r
470
MC/DC0%0/3
$precision //= $opts->{"precision"} // $self->precision
$precision $opts->{"precision"} $self->precision
Truth table0%0/4
A //= B // C
A= $precisionB= $opts->{"precision"}C= $self->precision
ABCresult
1XX1
01X1
0011
0000
714 16 ▶ my $thousands_sep = $opts->{thousand} // $self->thousand;
Condition66%2/3
$opts->{"thousand"} // $self->thousand
l!l&&r!l&&!r
4120
MC/DC0%0/2
$opts->{"thousand"} // $self->thousand
$opts->{"thousand"} $self->thousand
Truth table66%2/3
A // B
A= $opts->{"thousand"}B= $self->thousand
ABresult
1X1
011
000
715 16 ▶ my $decimal_point = $opts->{decimal} // $self->decimal;
Condition66%2/3
$opts->{"decimal"} // $self->decimal
l!l&&r!l&&!r
4120
MC/DC0%0/2
$opts->{"decimal"} // $self->decimal
$opts->{"decimal"} $self->decimal
Truth table66%2/3
A // B
A= $opts->{"decimal"}B= $self->decimal
ABresult
1X1
011
000
716 16 ▶ my $trailing_zeroes = $opts->{decimal_fill} // $self->decimal_fill // 1;
Condition40%2/5
($opts->{"decimal_fill"} // $self->decimal_fill) // 1
l!l
160
$opts->{"decimal_fill"} // $self->decimal_fill
l!l&&r!l&&!r
0160
MC/DC0%0/2
($opts->{"decimal_fill"} // $self->decimal_fill) // 1
$opts->{"decimal_fill"} $self->decimal_fill
Truth table33%1/3
A // B
A= $opts->{"decimal_fill"}B= $self->decimal_fill
ABresult
1X1
011
000
717 16 ▶ my $grouping = $opts->{grouping} // $self->grouping // 3;
Condition60%3/5
($opts->{"grouping"} // $self->grouping) // 3
l!l
160
$opts->{"grouping"} // $self->grouping
l!l&&r!l&&!r
4120
MC/DC0%0/2
($opts->{"grouping"} // $self->grouping) // 3
$opts->{"grouping"} $self->grouping
Truth table66%2/3
A // B
A= $opts->{"grouping"}B= $self->grouping
ABresult
1X1
011
000
718 16 for( $precision, $thousands_sep, $decimal_point, $trailing_zeroes, $grouping )
719 {
720 80 ▶ $_ = $_->scalar if( $self->_can( $_ => 'scalar' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_can($_, "scalar") 59 21 80
721 }
722 16 ▶ $grouping = 3 unless( $self->_is_integer( $grouping ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_integer($grouping) 0 16 16
723  
724 # Taken from Number::Format. Credit to William R. Ward
725 # Handle negative numbers
726 16 my $sign = $number <=> 0;
727 16 ▶ $number = CORE::abs( $number ) if( $sign < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $sign < 0 0 16 16
728  
729 # detect scientific notation
730 16 my $exponent = 0;
731 # if( $number =~ /^(-?[\d.]+)e([+-]\d+)$/ )
732 # {
733 # # Don't attempt to format numbers that require scientific notation.
734 # return( $number );
735 # }
736 # Detect scientific notation and preserve it exactly
737 # 1.23e+45
738 16 ▶ if( "$number" =~ /^(-?\d+(?:\.\d+)?)[eE]([+-]?\d+)+$/i )
Branch: 1 branch
BranchTrueFalseTotal
if ("$number" =~ /^(-?\d+(?:\.\d+)?)[eE]([+-]?\d+)+$/i) 1 15 16
739 {
740 1 my $mantissa = $1;
741 1 my $exponent = $2;
742 # Preserve the exact string representation without formatting
743 1 my $result = "$mantissa" . "e" . "$exponent";
744 1 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 1 0 1
745 1 return( Module::Generic::Scalar->new( $result ) );
746 }
747  
748 # round off $number
749 15 $number = $self->_round( $number => $precision );
750  
751 # Split integer and decimal parts of the number and add commas
752 15 my $integer = CORE::int( $number );
753 15 my $decimal;
754  
755 # Note: In perl 5.6 and up, string representation of a number
756 # automagically includes the locale decimal point. This way we
757 # will detect the decimal part correctly as long as the decimal
758 # point is 1 character.
759 15 ▶ if( CORE::length( $integer ) < CORE::length( $number ) )
Branch: 1 branch
BranchTrueFalseTotal
if (length $integer < length $number) 15 0 15
760 {
761 15 $decimal = CORE::substr( $number, CORE::length( $integer ) + 1 );
762 }
763 15 ▶ $decimal = '' unless( defined( $decimal ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $decimal 0 15 15
764  
765 # Add trailing 0's if $trailing_zeroes is set.
766 15 ▶ if( $trailing_zeroes && $precision > CORE::length( $decimal ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($trailing_zeroes and $precision > length $decimal) 0 15 15
Condition33%1/3
$trailing_zeroes and $precision > length $decimal
!ll&&!rl&&r
1500
MC/DC0%0/2
$trailing_zeroes and $precision > length $decimal
$trailing_zeroes $precision > length $decimal
Truth table33%1/3
A and B
A= $trailing_zeroesB= $precision > length $decimal
ABresult
0X0
100
111
767 {
768 0 $decimal .= '0' x ( $precision - CORE::length( $decimal ) );
769 }
770  
771 # Add the commas (or whatever is in thousands_sep). If thousands_sep is the empty
772 # string, do nothing.
773 15 ▶ if( $thousands_sep && $grouping > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($thousands_sep and $grouping > 0) 10 5 15
Condition100%3/3
$thousands_sep and $grouping > 0
!ll&&!rl&&r
3210
MC/DC100%2/2
$thousands_sep and $grouping > 0
$thousands_sep $grouping > 0
Truth table100%3/3
A and B
A= $thousands_sepB= $grouping > 0
ABresult
0X0
100
111
774 {
775 # Add leading 0's so length($integer) is divisible by 3
776 10 $integer = '0' x ( $grouping - ( CORE::length( $integer ) % $grouping ) ) . $integer;
777  
778 # Split $integer into groups of 3 characters and insert commas
779 # $integer = CORE::join( $thousands_sep, CORE::grep{ $_ ne '' } CORE::split( /(...)/, $integer ) );
780 10 $integer = CORE::join( $thousands_sep, CORE::grep{ $_ ne '' } CORE::split( /(.{$grouping})/, $integer ) );
781 # Taken from perllocale:
782 # Grouping goes from right to left (low to high digits).
783 # 1 while $integer =~ s/(\d)(\d{$grouping}($|$thousands_sep))/$1$thousands_sep$2/;
784  
785 # Strip off leading zeroes and optional thousands separator
786 10 $integer =~ s/^0+(?:\Q$thousands_sep\E)?//;
787 }
788 15 ▶ $integer = '0' if( $integer eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if $integer eq "" 0 15 15
789  
790 # Combine integer and decimal parts and return the result.
791 15 ▶ my $result = ( CORE::defined( $decimal ) && CORE::length( $decimal ) )
Branch: 1 branch
BranchTrueFalseTotal
defined $decimal && length $decimal ? : 15 0 15
Condition33%1/3
defined $decimal and length $decimal
!ll&&!rl&&r
0015
MC/DC0%0/2
defined $decimal and length $decimal
defined $decimal length $decimal
Truth table33%1/3
A and B
A= defined $decimalB= length $decimal
ABresult
0X0
100
111
792 ? CORE::join( $decimal_point, $integer, $decimal )
793 : $integer;
794  
795 15 ▶ my $res = ( $sign < 0 ) ? $self->_format_negative( $result ) : $result;
Branch: 1 branch
BranchTrueFalseTotal
$sign < 0 ? : 0 15 15
796 15 ▶ return( $self->pass_error ) if( !defined( $res ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $res and $self->error 0 15 15
Condition33%1/3
not defined $res and $self->error
!ll&&!rl&&r
1500
MC/DC0%0/2
not defined $res and $self->error
not defined $res $self->error
Truth table33%1/3
not(A) and B
A= not defined $resB= $self->error
ABresult
0X0
100
111
797 15 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 15 0 15
798 15 $self->clear_error;
799 15 return( Module::Generic::Scalar->new( $res ) );
800 }
801  
802 # sub format_binary { return( Module::Generic::Scalar->new( CORE::sprintf( '%b', shift->{_number} ) ) ); }
803 sub format_binary
804 2 ▶{
Subroutine format_binary: called CC=3 SCAR=11.3
Pod documented
805 2 my $self = shift( @_ );
806 2 ▶ return( $self->error( 'format_binary() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 2 2
807 2 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 2 0 2
808 2 $self->clear_error;
809 2 return( Module::Generic::Scalar->new( CORE::sprintf( '%b', $self->{_number} ) ) );
810 }
811  
812 sub format_bytes
813 5 ▶{
Subroutine format_bytes: called CC=25 SCAR=41.2
Pod documented
814 5 my $self = shift( @_ );
815 5 ▶ return( $self->error( 'format_bytes() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 5 5
816 # no overloading;
817 5 my $number = $self->{_number};
818 # See comment in format() method
819 5 ▶ return( $number ) if( !defined( $number ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 5 5
820 5 my $opts = $self->_get_args_as_hash( @_ );
821 5 ▶ return( $self->error( "Negative number not allowed in format_bytes()" ) ) if( $number < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $number < 0 0 5 5
822  
823 # Taken from Number::Format. Credit to William R. Ward
824 # Set default for precision. Test using defined because it may be 0.
825 5 ▶ $opts->{precision} //= $self->precision->scalar // 2;
Condition50%2/4
$opts->{"precision"} //= $self->precision->scalar // 2
l!l
05
$self->precision->scalar // 2
l!l
50
MC/DC0%0/1
$opts->{"precision"} //= $self->precision->scalar // 2
$opts->{"precision"}
Truth table50%1/2
A
A= $opts->{"precision"}
Aresult
11
00
826 5 ▶ $opts->{mode} ||= 'traditional';
Condition100%2/2
$opts->{"mode"} ||= "traditional"
l!l
23
MC/DC100%1/1
$opts->{"mode"} ||= "traditional"
$opts->{"mode"}
Truth table100%2/2
A
A= $opts->{"mode"}
Aresult
11
00
827 5 my( $ksuff, $msuff, $gsuff );
828 5 ▶ if( $opts->{mode} =~ /^iec(60027)?$/i )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'mode'} =~ /^iec(60027)?$/i) { } 2 3 5
elsif ($opts->{'mode'} =~ /^trad(itional)?$/i) { } 3 0 3
829 {
830 2 ( $ksuff, $msuff, $gsuff ) = @$self{ qw( kibi_suffix mebi_suffix gibi_suffix ) };
831 2 ▶ return( $self->error( "'base' option not allowed in iec60027 mode" ) ) if( CORE::exists( $opts->{base} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"base"} 0 2 2
832 }
833 elsif( $opts->{mode} =~ /^trad(itional)?$/i )
834 {
835 3 ( $ksuff, $msuff, $gsuff ) = @$self{ qw( kilo_suffix mega_suffix giga_suffix ) };
836 }
837 else
838 {
839 0 return( $self->error( "Unsupported mode '$opts->{mode}'" ) );
840 }
841  
842 # Set default for "base" option. Calculate threshold values for
843 # kilo, mega, and giga values. On 32-bit systems tera would cause
844 # overflows so it is not supported. Useful values of "base" are
845 # 1024 or 1000, but any number can be used. Larger numbers may
846 # cause overflows for giga or even mega, however.
847 5 ▶ my $mult = $self->_get_multipliers( $opts->{base} ) ||
Condition50%1/2
$self->_get_multipliers($opts->{'base'}) || (return $self->pass_error)
l!l
50
MC/DC0%0/1
$self->_get_multipliers($opts->{'base'}) || (return $self->pass_error)
$self->_get_multipliers($opts->{'base'})
Truth table50%1/2
A
A= $self->_get_multipliers($opts->{'base'})
Aresult
11
00
848 return( $self->pass_error );
849  
850 # Process "unit" option. Set default, then take first character
851 # and convert to upper case.
852 5 ▶ $opts->{unit} = 'auto' unless( defined( $opts->{unit} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"unit"} 5 0 5
853 5 my $unit = CORE::uc( CORE::substr( $opts->{unit}, 0, 1 ) );
854  
855 # Process "auto" first (default). Based on size of number,
856 # automatically determine which unit to use.
857 5 ▶ if( $unit eq 'A' )
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq "A") 5 0 5
858 {
859 5 ▶ if( $number >= $mult->{giga} )
Branch: 3 branches
BranchTrueFalseTotal
if ($number >= $mult->{'giga'}) { } 0 5 5
elsif ($number >= $mult->{'mega'}) { } 5 0 5
elsif ($number >= $mult->{'kilo'}) { } 0 0 0
860 {
861 0 $unit = 'G';
862 }
863 elsif( $number >= $mult->{mega} )
864 {
865 5 $unit = 'M';
866 }
867 elsif( $number >= $mult->{kilo} )
868 {
869 0 $unit = 'K';
870 }
871 else
872 {
873 0 $unit = 'N';
874 }
875 }
876  
877 # Based on unit, whether specified or determined above, divide the
878 # number and determine what suffix to use.
879 5 my $suffix = '';
880 5 ▶ if( $unit eq 'G' )
Branch: 4 branches
BranchTrueFalseTotal
if ($unit eq 'G') { } 0 5 5
elsif ($unit eq 'M') { } 5 0 5
elsif ($unit eq 'K') { } 0 0 0
elsif ($unit ne 'N') { } 0 0 0
881 {
882 0 $number /= $mult->{giga};
883 0 $suffix = $gsuff;
884 }
885 elsif( $unit eq 'M' )
886 {
887 5 $number /= $mult->{mega};
888 5 $suffix = $msuff;
889 }
890 elsif( $unit eq 'K' )
891 {
892 0 $number /= $mult->{kilo};
893 0 $suffix = $ksuff;
894 }
895 elsif( $unit ne 'N' )
896 {
897 0 return( $self->error( "Invalid 'unit' option value \"$unit\"" ) );
898 }
899  
900 # Format the number and add the suffix.
901 5 my $clone = $self->clone( $number );
902 5 ▶ return( $self->pass_error ) if( !defined( $clone ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $clone 0 5 5
903  
904 5 my $formatted = $clone->format( $opts->{precision} );
905 5 ▶ return( $self->pass_error ) if( !defined( $formatted ) && $clone->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $formatted and $clone->error 0 5 5
Condition33%1/3
not defined $formatted and $clone->error
!ll&&!rl&&r
500
MC/DC0%0/2
not defined $formatted and $clone->error
not defined $formatted $clone->error
Truth table33%1/3
not(A) and B
A= not defined $formattedB= $clone->error
ABresult
0X0
100
111
906  
907 5 my $result = "${formatted}${suffix}";
908  
909 5 ▶ return( $self->pass_error ) if( !defined( $result ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 5 5
910 5 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 5 0 5
911 5 $self->clear_error;
912 5 return( Module::Generic::Scalar->new( $result ) );
913 }
914  
915 sub format_hex
916 2 ▶{
Subroutine format_hex: called CC=3 SCAR=11.3
Pod documented
917 2 my $self = shift( @_ );
918 2 ▶ return( $self->error( 'format_hex() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 2 2
919 2 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 2 0 2
920 2 $self->clear_error;
921 2 return( Module::Generic::Scalar->new( CORE::sprintf( '0x%X', $self->{_number} ) ) );
922 }
923  
924 sub format_money
925 4 ▶{
Subroutine format_money: called CC=39 SCAR=51.4
Pod documented
926 4 my $self = shift( @_ );
927 4 my( $precision, $curr_symbol ) = @_;
928 4 ▶ return( $self->error( 'format_money() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 4 4
929 4 ▶ $precision = $self->precision->scalar if( !defined( $precision ) || !CORE::length( "$precision" ) || $precision !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $precision and length "$precision" and $precision =~ /^\d+$/ 4 0 4
Condition33%2/6
defined $precision and length "$precision" and $precision =~ /^\d+$/
!ll&&!rl&&r
400
defined $precision and length "$precision"
!ll&&!rl&&r
400
MC/DC0%0/3
defined $precision and length "$precision" and $precision =~ /^\d+$/
defined $precision length "$precision" $precision =~ /^\d+$/
Truth table25%1/4
A and B and C
A= defined $precisionB= length "$precision"C= $precision =~ /^\d+$/
ABCresult
0XX0
10X0
1100
1111
930 4 ▶ $curr_symbol = $self->currency->scalar if( !defined( $curr_symbol ) || !CORE::length( "$curr_symbol" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $curr_symbol and length "$curr_symbol" 4 0 4
Condition33%1/3
defined $curr_symbol and length "$curr_symbol"
!ll&&!rl&&r
400
MC/DC0%0/2
defined $curr_symbol and length "$curr_symbol"
defined $curr_symbol length "$curr_symbol"
Truth table33%1/3
A and B
A= defined $curr_symbolB= length "$curr_symbol"
ABresult
0X0
100
111
931 # no overloading;
932 4 my $number = $self->{_number};
933 # See comment in format() method
934 4 ▶ return( $number ) if( !defined( $number ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 4 4
935  
936 # NOTE: Money follows the LC_MONETARY category through the dedicated monetary trio
937 # resolved in init() (mon_decimal, mon_thousand, mon_grouping). We fall back to the
938 # numeric trio only when a monetary value was not resolved at all, so that a locale
939 # missing monetary data still produces a sensible result.
940 4 my $mon_decimal_point = $self->mon_decimal->scalar;
941 4 my $mon_thousands_sep = $self->mon_thousand->scalar;
942 4 my $mon_grouping = $self->mon_grouping->scalar;
943 4 ▶ $mon_decimal_point = $self->decimal->scalar if( !defined( $mon_decimal_point ) || !CORE::length( $mon_decimal_point ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mon_decimal_point and length $mon_decimal_point 0 4 4
Condition33%1/3
defined $mon_decimal_point and length $mon_decimal_point
!ll&&!rl&&r
004
MC/DC0%0/2
defined $mon_decimal_point and length $mon_decimal_point
defined $mon_decimal_point length $mon_decimal_point
Truth table33%1/3
A and B
A= defined $mon_decimal_pointB= length $mon_decimal_point
ABresult
0X0
100
111
944 4 ▶ $mon_thousands_sep = $self->thousand->scalar if( !defined( $mon_thousands_sep ) || !CORE::length( $mon_thousands_sep ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mon_thousands_sep and length $mon_thousands_sep 1 3 4
Condition66%2/3
defined $mon_thousands_sep and length $mon_thousands_sep
!ll&&!rl&&r
013
MC/DC50%1/2
defined $mon_thousands_sep and length $mon_thousands_sep
defined $mon_thousands_sep length $mon_thousands_sep
Truth table66%2/3
A and B
A= defined $mon_thousands_sepB= length $mon_thousands_sep
ABresult
0X0
100
111
945 4 ▶ $mon_grouping = $self->grouping->scalar if( !defined( $mon_grouping ) || !CORE::length( $mon_grouping ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mon_grouping and length $mon_grouping 0 4 4
Condition33%1/3
defined $mon_grouping and length $mon_grouping
!ll&&!rl&&r
004
MC/DC0%0/2
defined $mon_grouping and length $mon_grouping
defined $mon_grouping length $mon_grouping
Truth table33%1/3
A and B
A= defined $mon_groupingB= length $mon_grouping
ABresult
0X0
100
111
946  
947 4 my $frac_digits = $self->precision->scalar;
948  
949 # Determine precision for decimal portion
950 4 ▶ $precision = $frac_digits unless( defined( $precision ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $precision 0 4 4
951 # fallback
952 # $precision = $self->decimal_digits unless( defined( $precision ) );
953 # default
954 4 ▶ $precision = 2 unless( defined( $precision ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $precision 0 4 4
955  
956 # Determine sign and absolute value
957 4 my $sign = $number <=> 0;
958 4 ▶ $number = CORE::abs( $number ) if( $sign < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $sign < 0 0 4 4
959  
960 # format it first
961 4 $number = $self->format(
962 precision => $precision,
963 decimal => $mon_decimal_point,
964 thousand => $mon_thousands_sep,
965 grouping => $mon_grouping,
966 );
967 4 ▶ return( $self->pass_error ) if( !defined( $number ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 4 4
968  
969 # Now we make sure the decimal part has enough zeroes
970 4 my $decimal_point = $mon_decimal_point;
971 4 my( $integer, $decimal ) = CORE::split( /\Q$decimal_point\E/, "$number", 2 );
972 4 ▶ $decimal //= '';
Condition50%1/2
$decimal //= ""
l!l
40
MC/DC0%0/1
$decimal //= ""
$decimal
Truth table50%1/2
A
A= $decimal
Aresult
11
00
973 # $decimal = '0' x $precision if( !$decimal && $precision );
974 4 ▶ $decimal = '0' x $precision unless( $decimal );
Branch: 1 branch
BranchTrueFalseTotal
unless $decimal 0 4 4
975 4 $decimal .= '0' x ( $precision - CORE::length( $decimal ) );
976  
977 # Extract positive or negative values
978 4 my( $sep_by_space, $cs_precedes, $sign_posn, $sign_symbol );
979 4 ▶ if( $sign < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($sign < 0) { } 0 4 4
980 {
981 0 $sep_by_space = $self->space_neg;
982 0 $cs_precedes = $self->precede_neg;
983 0 $sign_posn = $self->position_neg;
984 0 ▶ $sign_symbol = $self->sign_neg // '';
Condition0%0/2
$self->sign_neg // ""
l!l
00
MC/DC0%0/1
$self->sign_neg // ""
$self->sign_neg
Truth table0%0/2
A
A= $self->sign_neg
Aresult
11
00
985 }
986 else
987 {
988 4 $sep_by_space = $self->space_pos;
989 4 $cs_precedes = $self->precede_pos;
990 4 $sign_posn = $self->position_pos;
991 4 ▶ $sign_symbol = $self->sign_pos // '';
Condition50%1/2
$self->sign_pos // ""
l!l
40
MC/DC0%0/1
$self->sign_pos // ""
$self->sign_pos
Truth table50%1/2
A
A= $self->sign_pos
Aresult
11
00
992 }
993  
994 # Combine it all back together.
995 4 ▶ my $result = $precision
Branch: 1 branch
BranchTrueFalseTotal
$precision ? : 4 0 4
996 ? CORE::join( $mon_decimal_point, $integer, $decimal )
997 : $integer;
998  
999 # Determine where spaces go, if any
1000 4 my( $sign_sep, $curr_sep );
1001 4 ▶ if( $sep_by_space == 0 )
Branch: 3 branches
BranchTrueFalseTotal
if ($sep_by_space == 0) { } 3 1 4
elsif ($sep_by_space == 1) { } 1 0 1
elsif ($sep_by_space == 2) { } 0 0 0
1002 {
1003 3 $sign_sep = $curr_sep = '';
1004 }
1005 elsif( $sep_by_space == 1 )
1006 {
1007 1 $sign_sep = '';
1008 1 $curr_sep = ' ';
1009 }
1010 elsif( $sep_by_space == 2 )
1011 {
1012 0 $sign_sep = ' ';
1013 0 $curr_sep = '';
1014 }
1015 else
1016 {
1017 0 return( $self->error( "Invalid space (space_neg or space_pos) value provided." ) );
1018 }
1019  
1020 4 my $rv;
1021 # Add sign, if any
1022 4 ▶ if( $sign_posn >= 0 && $sign_posn <= 2 )
Branch: 2 branches
BranchTrueFalseTotal
if ($sign_posn >= 0 and $sign_posn <= 2) { } 4 0 4
elsif ($sign_posn == 3 or $sign_posn == 4) { } 0 0 0
Condition33%1/3
$sign_posn >= 0 and $sign_posn <= 2
!ll&&!rl&&r
004
MC/DC0%0/2
$sign_posn >= 0 and $sign_posn <= 2
$sign_posn >= 0 $sign_posn <= 2
Truth table33%1/3
A and B
A= $sign_posn >= 0B= $sign_posn <= 2
ABresult
0X0
100
111
1023 {
1024 # Combine with currency symbol and return
1025 4 ▶ if( $curr_symbol ne '' )
Branch: 1 branch
BranchTrueFalseTotal
if ($curr_symbol ne "") 4 0 4
1026 {
1027 4 ▶ if( $cs_precedes )
Branch: 1 branch
BranchTrueFalseTotal
if ($cs_precedes) { } 0 4 4
1028 {
1029 0 $result = $curr_symbol . $curr_sep . $result;
1030 }
1031 else
1032 {
1033 4 $result = $result . $curr_sep . $curr_symbol;
1034 }
1035 }
1036  
1037 4 ▶ if( $sign_posn == 0 )
Branch: 2 branches
BranchTrueFalseTotal
if ($sign_posn == 0) { } 0 4 4
elsif ($sign_posn == 1) { } 4 0 4
1038 {
1039 0 $rv = "($result)";
1040 }
1041 elsif( $sign_posn == 1 )
1042 {
1043 4 $rv = $sign_symbol . $sign_sep . $result;
1044 }
1045 # $sign_posn == 2
1046 else
1047 {
1048 0 $rv = $result . $sign_sep . $sign_symbol;
1049 }
1050 }
1051 ▶ elsif( $sign_posn == 3 || $sign_posn == 4 )
Condition0%0/3
$sign_posn == 3 or $sign_posn == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$sign_posn == 3 or $sign_posn == 4
$sign_posn == 3 $sign_posn == 4
Truth table0%0/3
A or B
A= $sign_posn == 3B= $sign_posn == 4
ABresult
1X1
011
000
1052 {
1053 0 ▶ if( $sign_posn == 3 )
Branch: 1 branch
BranchTrueFalseTotal
if ($sign_posn == 3) { } 0 0 0
1054 {
1055 0 $curr_symbol = $sign_symbol . $sign_sep . $curr_symbol;
1056 }
1057 # $sign_posn == 4
1058 else
1059 {
1060 0 $curr_symbol = $curr_symbol . $sign_sep . $sign_symbol;
1061 }
1062  
1063 # Combine with currency symbol and return
1064 0 ▶ if( $cs_precedes )
Branch: 1 branch
BranchTrueFalseTotal
if ($cs_precedes) { } 0 0 0
1065 {
1066 0 $rv = $curr_symbol. $curr_sep . $result;
1067 }
1068 else
1069 {
1070 0 $rv = $result . $curr_sep . $curr_symbol;
1071 }
1072 }
1073 else
1074 {
1075 0 return( $self->error( "Invalid *_sign_posn value" ) );
1076 }
1077  
1078 4 ▶ return if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 4 4
1079 4 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 4 0 4
1080 4 $self->clear_error;
1081 4 return( Module::Generic::Scalar->new( $rv ) );
1082 }
1083  
1084 sub format_negative
1085 1 ▶{
Subroutine format_negative: called CC=7 SCAR=21.3
Pod documented
1086 1 my $self = shift( @_ );
1087 # no overloading;
1088 # my $number = $self->{_number};
1089 # See comment in format() method
1090 # return( $number ) if( !defined( $number ) );
1091 1 ▶ my $format = shift( @_ ) // $self->neg_format->scalar;
Condition33%1/3
shift @_ // $self->neg_format->scalar
l!l&&r!l&&!r
100
MC/DC0%0/2
shift @_ // $self->neg_format->scalar
shift @_ $self->neg_format->scalar
Truth table33%1/3
A // B
A= shift @_B= $self->neg_format->scalar
ABresult
1X1
011
000
1092 1 ▶ return( $self->error( 'format_negative() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
1093 1 ▶ my $new = $self->format || return( $self->pass_error );
Condition50%1/2
$self->format || (return $self->pass_error)
l!l
10
MC/DC0%0/1
$self->format || (return $self->pass_error)
$self->format
Truth table50%1/2
A
A= $self->format
Aresult
11
00
1094 1 my $number = "$new";
1095 1 ▶ if( CORE::index( $format, 'x' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($format, "x") == -1) 0 1 1
1096 {
1097 0 return( $self->error( "Letter x must be present in picture in format_negative()" ) );
1098 }
1099 1 $number =~ s/^-//;
1100 1 $format =~ s/x/$number/;
1101 1 ▶ return if( !defined( $number ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 1 1
1102 1 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 1 0 1
1103 1 $self->clear_error;
1104 1 return( Module::Generic::Scalar->new( $format ) );
1105 }
1106  
1107 sub format_picture
1108 0 ▶{
Subroutine format_picture: not called CC=33 SCAR=69.6
Pod documented
1109 0 my $self = shift( @_ );
1110 0 my $picture;
1111 0 ▶ if( ( scalar( @_ ) == 1 && !$self->_is_hash( $_[0] ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and not $self->_is_hash($_[0]) or @_ % 2 and not $self->_is_hash($_[0])) 0 0 0
Condition0%0/9
scalar @_ == 1 and not $self->_is_hash($_[0]) or @_ % 2 and not $self->_is_hash($_[0])
l!l&&r!l&&!r
000
scalar @_ == 1 and not $self->_is_hash($_[0])
!ll&&!rl&&r
000
@_ % 2 and not $self->_is_hash($_[0])
!ll&&!rl&&r
000
MC/DC0%0/4
scalar @_ == 1 and not $self->_is_hash($_[0]) or @_ % 2 and not $self->_is_hash($_[0])
scalar @_ == 1 not $self->_is_hash($_[0]) @_ % 2 not $self->_is_hash($_[0])
Truth table0%0/7
A and not(B) or C and not(D)
A= scalar @_ == 1B= not $self->_is_hash($_[0])C= @_ % 2D= not $self->_is_hash($_[0])
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1112 ( ( @_ % 2 ) && !$self->_is_hash( $_[0] ) ) )
1113 {
1114 0 $picture = shift( @_ );
1115 }
1116 0 my $opts = $self->_get_args_as_hash( @_ );
1117 0 ▶ return( $self->error( 'format_picture() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 0 0
1118 2 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
1119 0 my $number = $self->{_number};
1120 # See comment in format() method
1121 0 ▶ return if( !defined( $number ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 0 0
1122  
1123 # Taken from Number::Format. Credit to William R. Ward
1124 0 ▶ $picture //= $opts->{picture};
Condition0%0/3
$picture //= $opts->{"picture"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$picture //= $opts->{"picture"}
$picture $opts->{"picture"}
Truth table0%0/3
A //= B
A= $pictureB= $opts->{"picture"}
ABresult
1X1
011
000
1125 0 ▶ return( $self->error( "No picture was provided to format number." ) ) if( !CORE::defined( $picture ) || !CORE::length( "$picture" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $picture and length "$picture" 0 0 0
Condition0%0/3
defined $picture and length "$picture"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $picture and length "$picture"
defined $picture length "$picture"
Truth table0%0/3
A and B
A= defined $pictureB= length "$picture"
ABresult
0X0
100
111
1126  
1127 # Handle negative numbers
1128 0 my $neg_format = $self->neg_format->scalar;
1129 0 my( $neg_prefix ) = $neg_format =~ /^([^x]+)/;
1130 0 my( $pic_prefix ) = $picture =~ /^([^\#]+)/;
1131 0 my $neg_pic = $neg_format;
1132 0 ( my $pos_pic = $neg_format ) =~ s/[^x\s]/ /g;
1133 0 ( my $pos_prefix = $neg_prefix ) =~ s/[^x\s]/ /g;
1134 0 $neg_pic =~ s/x/$picture/;
1135 0 $pos_pic =~ s/x/$picture/;
1136 0 my $sign = $number <=> 0;
1137 0 ▶ $number = CORE::abs( $number ) if( $sign < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $sign < 0 0 0 0
1138 0 ▶ $picture = $sign < 0 ? $neg_pic : $pos_pic;
Branch: 1 branch
BranchTrueFalseTotal
$sign < 0 ? : 0 0 0
1139 0 ▶ my $sign_prefix = $sign < 0 ? $neg_prefix : $pos_prefix;
Branch: 1 branch
BranchTrueFalseTotal
$sign < 0 ? : 0 0 0
1140  
1141 # Split up the picture and return error if there is more than one $decimal_point
1142 0 my $decimal_point = $self->decimal->scalar;
1143 0 my( $pic_int, $pic_dec, @cruft ) = CORE::split( /\Q$decimal_point\E/, $picture );
1144 0 ▶ $pic_int = '' unless( defined( $pic_int ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pic_int 0 0 0
1145 0 ▶ $pic_dec = '' unless( defined( $pic_dec ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pic_dec 0 0 0
1146  
1147 0 ▶ return( $self->error( "Only one decimal separator permitted in picture" ) ) if( @cruft );
Branch: 1 branch
BranchTrueFalseTotal
if @cruft 0 0 0
1148  
1149 # Obtain precision from the length of the decimal part...
1150 # start with copying it
1151 0 my $precision = $pic_dec;
1152 # eliminate all non-# characters
1153 0 $precision =~ s/[^\#]//g;
1154 # take the length of the result
1155 0 $precision = CORE::length( $precision );
1156  
1157 # Format the number
1158 0 $number = $self->_round( $number => $precision );
1159  
1160 # Obtain the length of the integer portion just like we did for $precision
1161 # start with copying it
1162 0 my $intsize = $pic_int;
1163 # eliminate all non-# characters
1164 0 $intsize =~ s/[^\#]//g;
1165 # take the length of the result
1166 0 $intsize = CORE::length( $intsize );
1167  
1168 # Split up $number same as we did for $picture earlier
1169 0 my( $num_int, $num_dec ) = CORE::split( /\./, $number, 2 );
1170 0 ▶ $num_int = '' unless( defined( $num_int ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num_int 0 0 0
1171 0 ▶ $num_dec = '' unless( defined( $num_dec ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num_dec 0 0 0
1172  
1173 # Check if the integer part will fit in the picture
1174 0 ▶ if( CORE::length( $num_int ) > $intsize )
Branch: 1 branch
BranchTrueFalseTotal
if (length $num_int > $intsize) 0 0 0
1175 {
1176 # convert # to * and return it
1177 0 $picture =~ s/\#/\*/g;
1178 0 ▶ $pic_prefix = '' unless( defined( $pic_prefix ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pic_prefix 0 0 0
1179 0 $picture =~ s/^(\Q$sign_prefix\E)(\Q$pic_prefix\E)([[:blank:]\h]*)/$2$3$1/;
1180 0 return( Module::Generic::Scalar->new( $picture ) );
1181 }
1182  
1183 # Split each portion of number and picture into arrays of characters
1184 0 my @num_int = CORE::split( //, $num_int );
1185 0 my @num_dec = CORE::split( //, $num_dec );
1186 0 my @pic_int = CORE::split( //, $pic_int );
1187 0 my @pic_dec = CORE::split( //, $pic_dec );
1188  
1189 # Now we copy those characters into @result.
1190 0 my @result;
1191 0 ▶ if( $picture =~ /\Q$decimal_point\E/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($picture =~ /\Q$decimal_point\E/) 0 0 0
1192 {
1193 0 @result = ( $decimal_point )
1194 }
1195 # For each characture in the decimal part of the picture, replace '#'
1196 # signs with digits from the number.
1197 0 my $char;
1198 0 foreach $char ( @pic_dec )
1199 {
1200 0 ▶ $char = ( shift( @num_dec ) || 0 ) if( $char eq '#' );
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "#" 0 0 0
Condition0%0/2
shift @num_dec || 0
l!l
00
MC/DC0%0/1
shift @num_dec || 0
shift @num_dec
Truth table0%0/2
A
A= shift @num_dec
Aresult
11
00
1201 0 CORE::push( @result, $char );
1202 }
1203  
1204 # For each character in the integer part of the picture (moving right
1205 # to left this time), replace '#' signs with digits from the number,
1206 # or spaces if we've run out of numbers.
1207 0 my $thousand = $self->thousand->scalar;
1208 0 ▶ while( $char = CORE::pop( @pic_int ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($char = pop @pic_int) 0 0 0
1209 {
1210 0 ▶ $char = CORE::pop( @num_int ) if( $char eq '#' );
Branch: 1 branch
BranchTrueFalseTotal
if $char eq "#" 0 0 0
1211 0 ▶ if( !defined( $char ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $char or $char eq $thousand and $#num_int < 0) 0 0 0
Condition0%0/6
not defined $char or $char eq $thousand and $#num_int < 0
l!l&&r!l&&!r
000
$char eq $thousand and $#num_int < 0
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $char or $char eq $thousand and $#num_int < 0
not defined $char $char eq $thousand $#num_int < 0
Truth table0%0/4
not(A) or B and C
A= not defined $charB= $char eq $thousandC= $#num_int < 0
ABCresult
1XX1
0111
00X0
0100
1212 $char eq $thousand &&
1213 $#num_int < 0 )
1214 {
1215 0 $char = ' ';
1216 }
1217 0 CORE::unshift( @result, $char );
1218 }
1219  
1220 # Combine @result into a string and return it.
1221 0 my $result = CORE::join( '', @result );
1222 0 ▶ $sign_prefix = '' unless( defined( $sign_prefix ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sign_prefix 0 0 0
1223 0 ▶ $pic_prefix = '' unless( defined( $pic_prefix ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pic_prefix 0 0 0
1224 0 $result =~ s/^(\Q$sign_prefix\E)(\Q$pic_prefix\E)(\s*)/$2$3$1/;
1225  
1226 0 ▶ return if( !defined( $result ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 0 0
1227 0 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 0 0 0
1228 0 $self->clear_error;
1229 0 return( Module::Generic::Scalar->new( $result ) );
1230 }
1231  
1232 0 ▶sub gibi_suffix { return( shift->_set_get_prop( 'gibi_suffix', @_ ) ); }
Subroutine gibi_suffix: not called CC=1 SCAR=6.9
Pod documented
1233  
1234 0 ▶sub giga_suffix { return( shift->_set_get_prop( 'giga_suffix', @_ ) ); }
Subroutine giga_suffix: not called CC=1 SCAR=6.9
Pod documented
1235  
1236 34 ▶sub grouping { return( shift->_set_get_prop( 'grouping', @_ ) ); }
Subroutine grouping: called CC=1 SCAR=0.0
Pod documented
1237  
1238 0 ▶sub kibi_suffix { return( shift->_set_get_prop( 'kibi_suffix', @_ ) ); }
Subroutine kibi_suffix: not called CC=1 SCAR=6.9
Pod documented
1239  
1240 0 ▶sub kilo_suffix { return( shift->_set_get_prop( 'kilo_suffix', @_ ) ); }
Subroutine kilo_suffix: not called CC=1 SCAR=6.9
Pod documented
1241  
1242 0 ▶sub lang { return( shift->_set_get_scalar_as_object( 'locale', @_ ) ); }
Subroutine lang: not called CC=1 SCAR=6.9
Pod documented
1243  
1244 2 ▶sub locale { return( shift->_set_get_scalar_as_object( 'locale', @_ ) ); }
Subroutine locale: called CC=1 SCAR=0.0
Pod documented
1245  
1246 0 ▶sub mebi_suffix { return( shift->_set_get_prop( 'mebi_suffix', @_ ) ); }
Subroutine mebi_suffix: not called CC=1 SCAR=6.9
Pod documented
1247  
1248 0 ▶sub mega_suffix { return( shift->_set_get_prop( 'mega_suffix', @_ ) ); }
Subroutine mega_suffix: not called CC=1 SCAR=6.9
Pod documented
1249  
1250 24 ▶sub mon_decimal { return( shift->_set_get_prop( 'mon_decimal', @_ ) ); }
Subroutine mon_decimal: called CC=1 SCAR=0.0
Pod documented
1251  
1252 24 ▶sub mon_grouping { return( shift->_set_get_prop( 'mon_grouping', @_ ) ); }
Subroutine mon_grouping: called CC=1 SCAR=0.0
Pod documented
1253  
1254 24 ▶sub mon_thousand { return( shift->_set_get_prop( 'mon_thousand', @_ ) ); }
Subroutine mon_thousand: called CC=1 SCAR=0.0
Pod documented
1255  
1256 2 ▶sub neg_format { return( shift->_set_get_prop( 'neg_format', @_ ) ); }
Subroutine neg_format: called CC=1 SCAR=0.0
Pod documented
1257  
1258 1 ▶sub posix_strict { return( shift->_set_get_boolean( 'posix_strict', @_ ) ); }
Subroutine posix_strict: called CC=1 SCAR=0.0
Pod documented
1259  
1260 15 ▶sub position_neg { return( shift->_set_get_prop( 'position_neg', @_ ) ); }
Subroutine position_neg: called CC=1 SCAR=0.0
Pod documented
1261  
1262 19 ▶sub position_pos { return( shift->_set_get_prop( 'position_pos', @_ ) ); }
Subroutine position_pos: called CC=1 SCAR=0.0
Pod documented
1263  
1264 19 ▶sub precede { return( shift->_set_get_prop( 'precede', @_ ) ); }
Subroutine precede: called CC=1 SCAR=0.0
Pod documented
1265  
1266 15 ▶sub precede_neg { return( shift->_set_get_prop( 'precede_neg', @_ ) ); }
Subroutine precede_neg: called CC=1 SCAR=0.0
Pod documented
1267  
1268 4 ▶sub precede_pos { return( shift->_set_get_prop( 'precede', @_ ) ); }
Subroutine precede_pos: called CC=1 SCAR=0.0
Pod documented
1269  
1270 54 ▶sub precision { return( shift->_set_get_prop( 'precision', @_ ) ); }
Subroutine precision: called CC=1 SCAR=0.0
Pod documented
1271  
1272 # sub round { return( $_[0]->clone( CORE::sprintf( '%.*f', CORE::int( CORE::length( $_[1] ) ? $_[1] : 0 ), $_[0]->{_number} ) ) ); }
1273 sub round
1274 3 ▶{
Subroutine round: called CC=6 SCAR=19.7
Pod documented
1275 3 my $self = shift( @_ );
1276 3 ▶ return( $self->error( 'round() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 3 3
1277 3 my $precision;
1278 3 ▶ if( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 3 0 3
1279 {
1280 3 $precision = shift( @_ );
1281 3 ▶ if( !$self->_is_integer( $precision ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->_is_integer($precision)) { } 0 3 3
elsif ($precision < 0) { } 1 2 3
1282 {
1283 0 ▶ return( $self->error( "round() precision value provided '", ( $precision // '' ), "' is not an integer." ) );
Condition0%0/2
$precision // ""
l!l
00
MC/DC0%0/1
$precision // ""
$precision
Truth table0%0/2
A
A= $precision
Aresult
11
00
1284 }
1285 elsif( $precision < 0 )
1286 {
1287 1 return( $self->error( "round() precision provided '$precision' is negative. It must be positive." ) );
1288 }
1289 }
1290 else
1291 {
1292 0 return( $self->error( 'Usage: my $n2 = $n->round( $precision );' ) );
1293 }
1294 2 my $new = CORE::sprintf( '%.*f', $precision, $self->{_number} );
1295 2 $self->clear_error;
1296 2 return( $new );
1297 }
1298  
1299 sub round_zero
1300 2 ▶{
Subroutine round_zero: called CC=8 SCAR=28.2
Pod documented
1301 2 my $self = shift( @_ );
1302 2 my @args = @_;
1303 2 ▶ return( $self->error( 'round_zero() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 2 2
1304 2 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 2 0 2
1305 {
1306 2 ▶ my $val = @args ? shift( @args ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 0 2 2
1307 2 local $@;
1308 my $res = eval
1309 2 {
1310 defined( $val ) ? POSIX::round( $self->{_number}, $val ) : POSIX::round( $self->{_number} )
1311 2 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 2 2
1312 2 ▶ CORE::warn( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
1313 2 $self->clear_error;
1314 2 return( $res );
1315 }
1316 else
1317 {
1318 0 my $n = $self->{_number};
1319 # round to nearest, ties away from zero (same semantics as C99 round())
1320 0 my $res;
1321 0 ▶ if( $n >= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($n >= 0) { } 0 0 0
1322 {
1323 0 $res = CORE::int( $n + 0.5 );
1324 }
1325 else
1326 {
1327 0 $res = -CORE::int( -$n + 0.5 );
1328 }
1329 0 $self->clear_error;
1330 0 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
1331 0 return( $res );
1332 }
1333 }
1334  
1335 sub round2
1336 1 ▶{
Subroutine round2: called CC=14 SCAR=34.0
Pod documented
1337 1 my $self = shift( @_ );
1338 1 ▶ return( $self->error( 'round2() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
1339 2 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
1340 1 my $precision;
1341 1 ▶ if( scalar( @_ ) == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 1 0 1
1342 {
1343 1 $precision = shift( @_ );
1344 1 ▶ if( !$self->_is_integer( $precision ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->_is_integer($precision)) { } 0 1 1
elsif ($precision < 0) { } 0 1 1
1345 {
1346 0 ▶ return( $self->error( "precision value provided '", ( $precision // '' ), "' is not an integer." ) );
Condition0%0/2
$precision // ""
l!l
00
MC/DC0%0/1
$precision // ""
$precision
Truth table0%0/2
A
A= $precision
Aresult
11
00
1347 }
1348 elsif( $precision < 0 )
1349 {
1350 0 return( $self->error( "precision provided '$precision' is negative. It must be positive." ) );
1351 }
1352 }
1353 else
1354 {
1355 0 return( $self->error( 'Usage: my $n2 = $n->round2( $precision );' ) );
1356 }
1357 1 my $number = $self->{_number};
1358 # See comment in format() method
1359 1 ▶ return( $number ) if( !defined( $number ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $number 0 1 1
1360  
1361 1 ▶ unless( CORE::int( $precision ) == $precision )
Branch: 1 branch
BranchTrueFalseTotal
unless (int $precision == $precision) 0 1 1
1362 {
1363 0 return( $self->error( "precision option value must be integer" ) );
1364 }
1365  
1366 1 ▶ if( CORE::ref( $number ) && $number->isa( 'Math::BigFloat' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $number and $number->isa("Math::BigFloat")) 0 1 1
Condition33%1/3
ref $number and $number->isa("Math::BigFloat")
!ll&&!rl&&r
100
MC/DC0%0/2
ref $number and $number->isa("Math::BigFloat")
ref $number $number->isa("Math::BigFloat")
Truth table33%1/3
A and B
A= ref $numberB= $number->isa("Math::BigFloat")
ABresult
0X0
100
111
1367 {
1368 0 my $rounded = $number->copy;
1369 0 $rounded->precision( -$precision );
1370 0 $self->clear_error;
1371 0 ▶ return if( !defined( $rounded ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rounded 0 0 0
1372 0 return( $rounded );
1373 }
1374  
1375 1 my $sign = $number <=> 0;
1376 1 my $multiplier = ( 10 ** $precision );
1377 1 my $result = CORE::abs( $number );
1378 1 my $product = $result * $multiplier;
1379  
1380 1 ▶ if( $product > MAX_INT )
Branch: 1 branch
BranchTrueFalseTotal
if ($product > "9.00719925474099e+15") 0 1 1
1381 {
1382 0 return( $self->error( "round2() overflow. Try smaller precision or use Math::BigFloat" ) )
1383 }
1384  
1385 # We need to add 1e-14 to avoid some rounding errors due to the
1386 # way floating point numbers work - see string-eq test in t/round.t
1387 1 $result = CORE::int( $product + .5 + 1e-14 ) / $multiplier;
1388 1 ▶ $result = -$result if( $sign < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $sign < 0 0 1 1
1389 1 $self->clear_error;
1390 1 ▶ return if( !defined( $result ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 1 1
1391 1 return( $result );
1392 }
1393  
1394 sub set_locale
1395 0 ▶{
Subroutine set_locale: not called CC=11 SCAR=48.8
Pod documented
1396 0 my $self = shift( @_ );
1397 0 ▶ my $locale = shift( @_ ) ||
Condition0%0/2
shift @_ || (return $self->error('No locale was provided to set.'))
l!l
00
MC/DC0%0/1
shift @_ || (return $self->error('No locale was provided to set.'))
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1398 return( $self->error( "No locale was provided to set." ) );
1399 0 ▶ return( $self->error( 'set_locale() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 0 0
1400 0 ( $locale, my $locale_enc ) = split( /\./, $locale, 2 );
1401 0 $locale =~ tr/-/_/;
1402 0 ▶ $locale = join( '.', $locale, $locale_enc ) if( defined( $locale_enc ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $locale_enc 0 0 0
1403 # Lock the threads while we change the locale to check if it is available, and get its definition.
1404 0 my $default;
1405 0 lock( $LOCALE_LOCK ) if( HAS_THREADS );
1406 # try-catch
1407 0 local $@;
1408 # We wrap our checks for locale in an anonymous subroutine to catch any fatal exception.
1409 my $try_locale = sub
1410 0 ▶ {
Subroutine __ANON__: not called CC=12 SCAR=50.5
1411 0 my $accepted = shift( @_ );
1412 0 my $saved_locale = POSIX::setlocale( &POSIX::LC_ALL );
1413 my $restore_locale = sub
1414 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1415 # Set back the LC_ALL to what it was, because we do not want to disturb the user environment
1416 0 ▶ POSIX::setlocale( &POSIX::LC_ALL, $saved_locale ) if( defined( $saved_locale ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $saved_locale 0 0 0
1417 0 };
1418 0 my( $loc, $lconv, $encoding );
1419 # The user provided only a language code such as fr_FR. We try it, and also other known combination like fr_FR.UTF-8 and fr_FR.ISO-8859-1, fr_FR.ISO8859-1
1420 # Try several possibilities
1421 # RT https://rt.cpan.org/Public/Bug/Display.html?id=132664
1422 0 ▶ if( index( $accepted, '.' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($accepted, '.') == -1) { } 0 0 0
1423 {
1424 0 $loc = POSIX::setlocale( &POSIX::LC_ALL, $accepted );
1425 0 $accepted =~ s/^(?<locale>[a-z]{2,3})_(?<country>[a-z]{2})$/$+{locale}_\U$+{country}\E/;
1426 0 ▶ if( !$loc && CORE::exists( $SUPPORTED_LOCALES->{ $accepted } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $loc and exists $SUPPORTED_LOCALES->{$accepted}) 0 0 0
Condition0%0/3
not $loc and exists $SUPPORTED_LOCALES->{$accepted}
!ll&&!rl&&r
000
MC/DC0%0/2
not $loc and exists $SUPPORTED_LOCALES->{$accepted}
not $loc exists $SUPPORTED_LOCALES->{$accepted}
Truth table0%0/3
not(A) and B
A= not $locB= exists $SUPPORTED_LOCALES->{$accepted}
ABresult
0X0
100
111
1427 {
1428 0 foreach my $supported ( @{$SUPPORTED_LOCALES->{ $accepted }} )
1429 {
1430 0 ▶ if( ( $loc = POSIX::setlocale( &POSIX::LC_ALL, $supported ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($loc = POSIX::setlocale(&POSIX::LC_ALL, $supported)) 0 0 0
1431 {
1432 0 $accepted = $supported;
1433 0 last;
1434 }
1435 }
1436 }
1437 }
1438 # We got something like fr_FR.ISO-8859
1439 # The user is specific, so we try as is
1440 else
1441 {
1442 0 $loc = POSIX::setlocale( &POSIX::LC_ALL, $accepted );
1443 }
1444  
1445 0 ▶ if( $loc )
Branch: 1 branch
BranchTrueFalseTotal
if ($loc) 0 0 0
1446 {
1447 # Encode and I18N::Langinfo are both core modules since before perl 5.26.1, which is our minimum requirement
1448 0 ▶ if( !$self->_load_class( 'Encode' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_load_class("Encode")) 0 0 0
1449 {
1450 0 $restore_locale->();
1451 0 die( $self->error );
1452 }
1453 0 ▶ if( !$self->_load_class( 'I18N::Langinfo' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_load_class("I18N::Langinfo")) 0 0 0
1454 {
1455 0 $restore_locale->();
1456 0 die( $self->error );
1457 }
1458 0 $lconv = POSIX::localeconv();
1459 # We do not want to pollute our local $@ at the beginning of 'set_locale'
1460 0 local $@;
1461 $encoding = eval
1462 0 ▶ {
Condition0%0/2
eval { do { &Encode::resolve_alias(scalar I18N::Langinfo::langinfo(I18N::Langinfo::CODESET())) } } || 'utf-8'
l!l
00
MC/DC0%0/1
eval { do { &Encode::resolve_alias(scalar I18N::Langinfo::langinfo(I18N::Langinfo::CODESET())) } } || 'utf-8'
eval { do { &Encode::resolve_alias(scalar I18N::Langinfo::langinfo(I18N::Langinfo::CODESET())) } }
Truth table0%0/2
A
A= eval { do { &Encode::resolve_alias(scalar I18N::Langinfo::langinfo(I18N::Langinfo::CODESET())) } }
Aresult
11
00
1463 0 Encode::resolve_alias( I18N::Langinfo::langinfo( I18N::Langinfo::CODESET() ) );
1464 } || 'utf-8';
1465 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
1466 {
1467 0 ▶ warn( "Error trying to resolve alias for POSIX::localeconv codeset: $@" ) if( $self->_is_warnings_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_warnings_enabled("Module::Generic") 0 0 0
1468 }
1469 }
1470 0 $restore_locale->();
1471 0 return( $loc, $lconv, $encoding, $accepted );
1472 0 };
1473
1474 0 my( $loc, $lconv, $encoding, $accepted ) = eval{ $try_locale->( $locale ) };
1475 0 ▶ if( $loc )
Branch: 2 branches
BranchTrueFalseTotal
if ($loc) { } 0 0 0
elsif ($@) { } 0 0 0
1476 {
1477 0 $self->encoding( $encoding ); # could be undef
1478 0 ▶ if( $lconv && scalar( keys( %$lconv ) ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($lconv and scalar keys %$lconv) 0 0 0
Condition0%0/2
$lconv and scalar keys %$lconv
!ll
00
MC/DC0%0/1
$lconv and scalar keys %$lconv
$lconv
Truth table0%0/2
A
A= $lconv
Aresult
00
11
1479 {
1480 0 $lconv->{grouping} = $self->_normalise_lconv_grouping( $lconv->{grouping} );
1481 0 $lconv->{mon_grouping} = $self->_normalise_lconv_grouping( $lconv->{mon_grouping} );
1482 0 $default = $lconv;
1483 0 ▶ if( my $decoded = $self->decode_lconv( $default ) )
Branch: 1 branch
BranchTrueFalseTotal
if (my $decoded = $self->decode_lconv($default)) 0 0 0
1484 {
1485 0 ▶ $self->_propagate_values( $decoded ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_propagate_values($decoded) or return $self->pass_error 0 0 0
1486 }
1487 }
1488 }
1489 elsif( $@ )
1490 {
1491 0 return( $self->error( "An error occurred while getting the locale information for \"$locale\": $@" ) );
1492 }
1493 else
1494 {
1495 0 return( $self->error( "Language \"$locale\" is not supported by your system." ) );
1496 }
1497  
1498 0 ▶ unless( defined( $accepted ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $accepted) 0 0 0
1499 {
1500 0 return( $self->error( "An unexpected error occurred while setting the locale \"$locale\": the accepted locale was not returned." ) );
1501 }
1502 0 $self->{locale} = $accepted;
1503 0 $self->clear_error;
1504 0 return( $self->{locale} );
1505 }
1506  
1507 15 ▶sub sign_neg { return( shift->_set_get_prop( 'sign_neg', @_ ) ); }
Subroutine sign_neg: called CC=1 SCAR=0.0
Pod documented
1508  
1509 19 ▶sub sign_pos { return( shift->_set_get_prop( 'sign_pos', @_ ) ); }
Subroutine sign_pos: called CC=1 SCAR=0.0
Pod documented
1510  
1511 15 ▶sub space_neg { return( shift->_set_get_prop( 'space_neg', @_ ) ); }
Subroutine space_neg: called CC=1 SCAR=0.0
Pod documented
1512  
1513 22 ▶sub space_pos { return( shift->_set_get_prop( 'space_pos', @_ ) ); }
Subroutine space_pos: called CC=1 SCAR=0.0
Pod documented
1514  
1515 16 ▶sub symbol { return( shift->_set_get_prop( 'symbol', @_ ) ); }
Subroutine symbol: called CC=1 SCAR=0.0
Pod documented
1516  
1517 34 ▶sub thousand { return( shift->_set_get_prop( 'thousand', @_ ) ); }
Subroutine thousand: called CC=1 SCAR=0.0
Pod documented
1518  
1519 sub unformat
1520 3 ▶{
Subroutine unformat: called CC=13 SCAR=26.4
Pod documented
1521 3 my $self = shift( @_ );
1522 3 my $formatted = shift( @_ );
1523 3 ▶ return( $self->error( 'unformat() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 3 3
1524 3 ▶ return( $self->error( "No value to unformat was provided." ) ) if( !defined( $formatted ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $formatted 0 3 3
1525 3 my $opts = $self->_get_args_as_hash( @_ );
1526 # require at least one digit
1527 3 ▶ unless( $formatted =~ /\d/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($formatted =~ /\d/) 1 2 3
1528 {
1529 1 return( $self->error( "Invalid number ${formatted} (", $self->_str_val( $formatted ), ")" ) );
1530 }
1531 2 my $num = $formatted;
1532  
1533 # Regular expression for detecting decimal point
1534 2 my $decimal_point = $self->decimal->scalar;
1535 2 my $pt = qr/\Q$decimal_point\E/;
1536  
1537 # Detect if it ends with one of the kilo / mega / giga suffixes.
1538 2 my( $kilo, $mega, $giga, $kibi, $mebi, $gibi ) = @$self{qw( kilo_suffix mega_suffix giga_suffix kibi_suffix mebi_suffix gibi_suffix )};
1539 2 my $kp = ( $formatted =~ s/[[:blank:]\h]*($kilo|$kibi)[[:blank:]\h]*$// );
1540 2 my $mp = ( $formatted =~ s/[[:blank:]\h]*($mega|$mebi)[[:blank:]\h]*$// );
1541 2 my $gp = ( $formatted =~ s/[[:blank:]\h]*($giga|$gibi)[[:blank:]\h]*$// );
1542 2 my $mult = $self->_get_multipliers( $opts->{base} );
1543  
1544 # Split number into integer and decimal parts
1545 2 my( $integer, $decimal, @cruft ) = CORE::split( $pt, $formatted );
1546 2 ▶ return( $self->error( "Only one decimal separator permitted" ) ) if( @cruft );
Branch: 1 branch
BranchTrueFalseTotal
if @cruft 0 2 2
1547  
1548 # It's negative if the first non-digit character is a -
1549 2 ▶ my $sign = $formatted =~ /^\D*-/ ? -1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$formatted =~ /^\D*-/ ? : 0 2 2
1550 2 my $neg_format = $self->neg_format->scalar;
1551 2 my( $before_re, $after_re ) = CORE::split( /x/, $neg_format, 2 );
1552 2 ▶ $sign = -1 if( $formatted =~ /\Q$before_re\E(.+)\Q$after_re\E/ );
Branch: 1 branch
BranchTrueFalseTotal
if $formatted =~ /\Q$before_re\E(.+)\Q$after_re\E/ 0 2 2
1553  
1554 # Strip out all non-digits from integer and decimal parts
1555 2 ▶ $integer = '' unless( defined( $integer ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $integer 0 2 2
1556 2 ▶ $decimal = '' unless( defined( $decimal ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $decimal 1 1 2
1557 2 $integer =~ s/\D//g;
1558 2 $decimal =~ s/\D//g;
1559  
1560 # Join back up, using period, and add 0 to make Perl think it's a number
1561 2 my $num2 = CORE::join( '.', $integer, $decimal ) + 0;
1562 2 ▶ $num2 = -$num2 if( $sign < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $sign < 0 0 2 2
1563  
1564 # Scale the number if it ended in kilo or mega suffix.
1565 2 ▶ $num2 *= $mult->{kilo} if( $kp );
Branch: 1 branch
BranchTrueFalseTotal
if $kp 0 2 2
1566 2 ▶ $num2 *= $mult->{mega} if( $mp );
Branch: 1 branch
BranchTrueFalseTotal
if $mp 0 2 2
1567 2 ▶ $num2 *= $mult->{giga} if( $gp );
Branch: 1 branch
BranchTrueFalseTotal
if $gp 0 2 2
1568 2 $self->clear_error;
1569 2 return( $num2 );
1570 }
1571  
1572 # Shared with format() and format_negative()
1573 sub _format_negative
1574 0 ▶{
Subroutine _format_negative: not called CC=4 SCAR=30.0
1575 0 my( $self, $number, $format ) = @_;
1576 0 ▶ return( $self->error( '_format_negative() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 0 0
1577 0 ▶ $format //= $self->neg_format->scalar;
Condition0%0/3
$format //= $self->neg_format->scalar
l!l&&r!l&&!r
000
MC/DC0%0/2
$format //= $self->neg_format->scalar
$format $self->neg_format->scalar
Truth table0%0/3
A //= B
A= $formatB= $self->neg_format->scalar
ABresult
1X1
011
000
1578 0 ▶ if( CORE::index( $format, 'x' ) == -1 )
Branch: 1 branch
BranchTrueFalseTotal
if (index($format, "x") == -1) 0 0 0
1579 {
1580 0 return( $self->error( "Letter x must be present in picture in format_negative()" ) );
1581 }
1582 0 $number =~ s/^-//;
1583 0 $format =~ s/x/$number/;
1584 0 $self->clear_error;
1585 0 return( $format );
1586 }
1587  
1588 # _get_multipliers returns the multipliers to be used for kilo, mega,
1589 # and giga (un-)formatting. Used in format_bytes and unformat_number.
1590 # For internal use only.
1591 sub _get_multipliers
1592 8 ▶{
Subroutine _get_multipliers: called CC=7 SCAR=27.6
1593 8 my $self = shift( @_ );
1594 8 my $base = shift( @_ );
1595 8 ▶ if( !defined( $base ) || $base == 1024 )
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $base or $base == 1024) { } 6 2 8
elsif ($base == 1000) { } 2 0 2
Condition66%2/3
not defined $base or $base == 1024
l!l&&r!l&&!r
602
MC/DC50%1/2
not defined $base or $base == 1024
not defined $base $base == 1024
Truth table66%2/3
not(A) or B
A= not defined $baseB= $base == 1024
ABresult
1X1
011
000
1596 {
1597 return({
1598 6 kilo => 0x00000400,
1599 mega => 0x00100000,
1600 giga => 0x40000000
1601 });
1602 }
1603 elsif( $base == 1000 )
1604 {
1605 return({
1606 2 kilo => 1_000,
1607 mega => 1_000_000,
1608 giga => 1_000_000_000
1609 });
1610 }
1611 else
1612 {
1613 0 ▶ return( $self->error( "base overflow" ) ) if( $base **3 > MAX_INT );
Branch: 1 branch
BranchTrueFalseTotal
if $base ** 3 > "9.00719925474099e+15" 0 0 0
1614 0 ▶ unless( $base > 0 && $base == CORE::int( $base ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($base > 0 and $base == int $base) 0 0 0
Condition0%0/3
$base > 0 and $base == int $base
!ll&&!rl&&r
000
MC/DC0%0/2
$base > 0 and $base == int $base
$base > 0 $base == int $base
Truth table0%0/3
A and B
A= $base > 0B= $base == int $base
ABresult
0X0
100
111
1615 {
1616 0 return( $self->error( "base must be a positive integer" ) );
1617 }
1618 return({
1619 0 kilo => $base,
1620 mega => $base ** 2,
1621 giga => $base ** 3
1622 });
1623 }
1624 }
1625  
1626 # NOTE: POSIX::localeconv()->{grouping} and {mon_grouping} are not simple scalar
1627 # integers. Per POSIX, they are byte strings where each byte indicates the size of one
1628 # digit group, applied from the lowest order to the highest.
1629 # Two byte values have special meaning:
1630 # 0 repeat the previous element for the rest of the digits.
1631 # CHAR_MAX no further grouping is to be performed.
1632 # CHAR_MAX is platform-dependent: on systems where char is signed it is 127 (SCHAR_MAX),
1633 # on systems where char is unsigned it is 255 (UCHAR_MAX). We treat any value >= 127 as
1634 # "stop grouping", which covers both cases since a legitimate group size never exceeds
1635 # a handful of units.
1636 # An empty string, undef, or a leading 0 byte all mean "no grouping".
1637 sub _normalise_lconv_grouping
1638 30 ▶{
Subroutine _normalise_lconv_grouping: called CC=7 SCAR=34.2
1639 30 my $self = shift( @_ );
1640 30 my $value = shift( @_ );
1641 30 ▶ return(0) if( !defined( $value ) || !CORE::length( $value ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 30 0 30
Condition33%1/3
defined $value and length $value
!ll&&!rl&&r
0300
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
1642 0 my @grouping = unpack( 'C*', $value );
1643 0 ▶ return(0) if( !scalar( @grouping ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @grouping 0 0 0
1644 0 my $first = $grouping[0];
1645 0 ▶ return(0) if( !defined( $first ) || $first == 0 || $first >= 127 );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $first or $first == 0 or $first >= 127 0 0 0
Condition0%0/6
not defined $first or $first == 0 or $first >= 127
l!l&&r!l&&!r
000
not defined $first or $first == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $first or $first == 0 or $first >= 127
not defined $first $first == 0 $first >= 127
Truth table0%0/4
not(A) or B or C
A= not defined $firstB= $first == 0C= $first >= 127
ABCresult
1XX1
01X1
0011
0000
1646 0 return( $first );
1647 }
1648  
1649 sub _propagate_values
1650 15 ▶{
Subroutine _propagate_values: called CC=14 SCAR=29.7
1651 15 my $self = shift( @_ );
1652 15 ▶ my $default = shift( @_ ) || return( $self->error( "No data was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No data was provided.'))
l!l
150
MC/DC0%0/1
shift @_ || (return $self->error('No data was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1653 2 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1654 15 ▶ my $active_map = $self->{posix_strict} ? $map_posix_strict : $map_flexible;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'posix_strict'} ? : 15 0 15
1655 15 foreach my $prop ( keys( %$active_map ) )
1656 {
1657 240 my $ref = $active_map->{ $prop };
1658 # Already set by user
1659 240 ▶ next if( CORE::length( $self->{ $prop } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{$prop} 0 240 240
1660 240 foreach my $lconv_prop ( @$ref )
1661 {
1662 240 ▶ if( CORE::defined( $default->{ $lconv_prop } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $default->{$lconv_prop}) { } 240 0 240
1663 {
1664 # Number::Format bug RT #71044 when running on Windows
1665 # https://rt.cpan.org/Ticket/Display.html?id=71044
1666 # This is a workaround when values are lower than 0 (i.e. -1)
1667 240 ▶ if( CORE::exists( $numerics->{ $lconv_prop } ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (exists $numerics->{$lconv_prop} and length $default->{$lconv_prop} and $default->{$lconv_prop} =~ /\d+/ and $default->{$lconv_prop} < 0) { } 105 135 240
elsif (not length $default->{$lconv_prop} and exists $numerics->{$lconv_prop}) { } 0 180 180
Condition77%7/9
exists $numerics->{$lconv_prop} and length $default->{$lconv_prop} and $default->{$lconv_prop} =~ /\d+/ and $default->{$lconv_prop} < 0
!ll&&!rl&&r
10530105
exists $numerics->{$lconv_prop} and length $default->{$lconv_prop} and $default->{$lconv_prop} =~ /\d+/
!ll&&!rl&&r
1050135
exists $numerics->{$lconv_prop} and length $default->{$lconv_prop}
!ll&&!rl&&r
1050135
MC/DC50%2/4
exists $numerics->{$lconv_prop} and length $default->{$lconv_prop} and $default->{$lconv_prop} =~ /\d+/ and $default->{$lconv_prop} < 0
exists $numerics->{$lconv_prop} length $default->{$lconv_prop} $default->{$lconv_prop} =~ /\d+/ $default->{$lconv_prop} < 0
Truth table60%3/5
A and B and C and D
A= exists $numerics->{$lconv_prop}B= length $default->{$lconv_prop}C= $default->{$lconv_prop} =~ /\d+/D= $default->{$lconv_prop} < 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1668 CORE::length( $default->{ $lconv_prop } ) &&
1669 # It may be a non-numeric value which would wreak the following condition
1670 $default->{ $lconv_prop } =~ /\d+/ &&
1671 $default->{ $lconv_prop } < 0 )
1672 {
1673 105 $default->{ $lconv_prop } = $numerics->{ $lconv_prop };
1674 }
1675 # POSIX::localeconv returned an incomplete hash and we need certain default values
1676 # For example a locale C.UTF-8 would only have the property decimal_point set to '.' and nothing else
1677 ▶ elsif( !CORE::length( $default->{ $lconv_prop } ) &&
Condition66%2/3
not length $default->{$lconv_prop} and exists $numerics->{$lconv_prop}
!ll&&!rl&&r
45900
MC/DC0%0/2
not length $default->{$lconv_prop} and exists $numerics->{$lconv_prop}
not length $default->{$lconv_prop} exists $numerics->{$lconv_prop}
Truth table66%2/3
not(A) and B
A= not length $default->{$lconv_prop}B= exists $numerics->{$lconv_prop}
ABresult
0X0
100
111
1678 CORE::exists( $numerics->{ $lconv_prop } ) )
1679 {
1680 0 $default->{ $lconv_prop } = $numerics->{ $lconv_prop };
1681 }
1682 240 $self->$prop( $default->{ $lconv_prop } );
1683 240 last;
1684 }
1685 # Set it to undef then
1686 else
1687 {
1688 0 ▶ if( CORE::exists( $numerics->{ $lconv_prop } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $numerics->{$lconv_prop}) 0 0 0
1689 {
1690 0 $default->{ $lconv_prop } = $numerics->{ $lconv_prop };
1691 }
1692 0 $self->$prop( $default->{ $lconv_prop } );
1693 }
1694 }
1695 }
1696 15 return( $self );
1697 }
1698  
1699 sub _round
1700 15 ▶{
Subroutine _round: called CC=1 SCAR=0.0
1701 15 my( $self, $num, $precision ) = @_;
1702 15 $self->clear_error;
1703 15 return( CORE::sprintf( '%.*f', $precision, $num ) );
1704 }
1705  
1706 sub _set_get_prop
1707 421 ▶{
Subroutine _set_get_prop: called CC=7 SCAR=19.7
1708 421 my $self = shift( @_ );
1709 421 my $prop = shift( @_ );
1710 421 ▶ return( $self->error( "${prop}() can only be called on an instance of ", __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 421 421
1711 421 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 290 131 421
1712 {
1713 290 my $val = shift( @_ );
1714 # $val = $val->scalar if( $self->_is_object( $val ) && $val->isa( 'Module::Generic::Scalar' ) );
1715 290 ▶ $val = "$val" if( CORE::defined( $val ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 290 0 290
1716 # I do not want to set a default value of '' to $self->{ $prop } because if its value is undef, it should remain so
1717 2 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1718 290 ▶ if( !CORE::defined( $val ) || ( CORE::defined( $val ) && $val ne $self->{ $prop } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val or defined $val and $val ne $self->{$prop}) 186 104 290
Condition66%4/6
not defined $val or defined $val and $val ne $self->{$prop}
l!l&&r!l&&!r
0186104
defined $val and $val ne $self->{$prop}
!ll&&!rl&&r
0104186
MC/DC33%1/3
not defined $val or defined $val and $val ne $self->{$prop}
not defined $val defined $val $val ne $self->{$prop}
Truth table50%2/4
not(A) or B and C
A= not defined $valB= defined $valC= $val ne $self->{$prop}
ABCresult
1XX1
0111
00X0
0100
1719 {
1720 186 $self->_set_get_scalar_as_object( $prop, $val );
1721 # If an error was set, we return nothing
1722 # $self->formatter( $self->new_formatter ) || return;
1723 }
1724 }
1725 421 $self->clear_error;
1726 421 return( $self->_set_get_scalar_as_object( $prop ) );
1727 }
1728  
1729 sub FREEZE
1730 0 ▶{
Subroutine FREEZE: not called CC=8 SCAR=42.8
Pod undocumented
1731 0 my $self = CORE::shift( @_ );
1732 0 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition0%0/2
shift @_ // ""
l!l
00
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
1733 0 my $class = CORE::ref( $self );
1734  
1735 # We keep a strict allow-list to avoid accidentally freezing DBI handles or other
1736 # process-local state.
1737 0 my @props = ( @{$self->{_fields}}, keys( %$map ) );
1738  
1739 0 my $hash = {};
1740 0 foreach my $prop ( @props )
1741 {
1742 0 ▶ if( CORE::exists( $self->{ $prop } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE") 0 0 0
Condition0%0/6
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
!ll&&!rl&&r
000
exists $self->{$prop} and defined $self->{$prop}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
exists $self->{$prop} defined $self->{$prop} ref $self->{$prop} ne "CODE"
Truth table0%0/4
A and B and C
A= exists $self->{$prop}B= defined $self->{$prop}C= ref $self->{$prop} ne "CODE"
ABCresult
0XX0
10X0
1100
1111
1743 defined( $self->{ $prop } ) &&
1744 CORE::ref( $self->{ $prop } ) ne 'CODE' )
1745 {
1746 0 $hash->{ $prop } = $self->{ $prop };
1747 }
1748 }
1749  
1750 # Return an array reference rather than a list so this works with Sereal and CBOR.
1751 # On or before Sereal version 4.023, Sereal did not support multiple values returned.
1752 0 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 0 0 0
1753 {
1754 0 require Sereal::Encoder;
1755 0 require version;
1756  
1757 0 ▶ if( version->parse( Sereal::Encoder->VERSION ) <= version->parse( '4.023' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("Sereal::Encoder"->VERSION) <= "version"->parse("4.023")) 0 0 0
1758 {
1759 0 CORE::return( [$class, $hash] );
1760 }
1761 }
1762  
1763 # But Storable wants a list with the first element being the serialised element
1764 0 CORE::return( $class, $hash );
1765 }
1766  
1767 0 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: not called CC=1 SCAR=6.9
Pod undocumented
1768  
1769 0 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: not called CC=1 SCAR=6.9
Pod undocumented
1770  
1771 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
1772 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
1773 sub THAW
1774 0 ▶{
Subroutine THAW: not called CC=10 SCAR=47.0
Pod undocumented
1775 0 my( $self, undef, @args ) = @_;
1776 0 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 0 0
Condition0%0/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table0%0/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
1777 0 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 0 0 0
Condition0%0/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
000
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
000
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table0%0/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
1778 0 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 0 0 0
1779 0 my $new;
1780 # Storable pattern requires to modify the object it created rather than returning a new one
1781 0 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 0 0 0
1782 {
1783 0 foreach( CORE::keys( %$hash ) )
1784 {
1785 0 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
1786 }
1787 0 $new = $self;
1788 }
1789 else
1790 {
1791 0 $new = CORE::bless( $hash => $class );
1792 }
1793 0 CORE::return( $new );
1794 }
1795  
1796 0 ▶sub TO_JSON { return( shift->as_number ); }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
1797  
1798  
1799 2 1;
1800 # NOTE: POD
1801 __END__
« lib/Module/Generic/Dynamic.pm ↑ Summary lib/Module/Generic/Global.pm »