XLSX/Fmt2007.pm

filter: Statementstmt 81.4% 44 / 54 Branchbran 60.0% 18 / 30 Conditioncond 33.3% 7 / 21 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 6 totaltotal 59.8% 79 / 132 CC 23 SCAR 26.0
CC
23
Cov
66%
ChkType
42.0
FmtString
11.3
FmtStringDef
4.9
CRAP 13.5
« XLSX.pm ↑ Summary
1 package Spreadsheet::XLSX::Fmt2007;
2 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 26 ▶use Spreadsheet::XLSX::Utility2007 qw(ExcelFmt);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 26 our $VERSION = '0.21'; #
7  
8 26 my %hFmtDefault = (
9 0x00 => '@',
10 0x01 => '0',
11 0x02 => '0.00',
12 0x03 => '#,##0',
13 0x04 => '#,##0.00',
14 0x05 => '($#,##0_);($#,##0)',
15 0x06 => '($#,##0_);[RED]($#,##0)',
16 0x07 => '($#,##0.00_);($#,##0.00_)',
17 0x08 => '($#,##0.00_);[RED]($#,##0.00_)',
18 0x09 => '0%',
19 0x0A => '0.00%',
20 0x0B => '0.00E+00',
21 0x0C => '# ?/?',
22 0x0D => '# ??/??',
23 0x0E => 'yyyy-mm-dd',
24 0x0F => 'd-mmm-yy',
25 0x10 => 'd-mmm',
26 0x11 => 'mmm-yy',
27 0x12 => 'h:mm AM/PM',
28 0x13 => 'h:mm:ss AM/PM',
29 0x14 => 'h:mm',
30 0x15 => 'h:mm:ss',
31 0x16 => 'm-d-yy h:mm',
32  
33 #0x17-0x24 -- Differs in Natinal
34 0x25 => '(#,##0_);(#,##0)',
35 0x26 => '(#,##0_);[RED](#,##0)',
36 0x27 => '(#,##0.00);(#,##0.00)',
37 0x28 => '(#,##0.00);[RED](#,##0.00)',
38 0x29 => '_(*#,##0_);_(*(#,##0);_(*"-"_);_(@_)',
39 0x2A => '_($*#,##0_);_($*(#,##0);_(*"-"_);_(@_)',
40 0x2B => '_(*#,##0.00_);_(*(#,##0.00);_(*"-"??_);_(@_)',
41 0x2C => '_($*#,##0.00_);_($*(#,##0.00);_(*"-"??_);_(@_)',
42 0x2D => 'mm:ss',
43 0x2E => '[h]:mm:ss',
44 0x2F => 'mm:ss.0',
45 0x30 => '##0.0E+0',
46 0x31 => '@',
47 );
48  
49 #------------------------------------------------------------------------------
50 # new (for Spreadsheet::XLSX::Fmt2007)
51 #------------------------------------------------------------------------------
52 282 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
53 282 my ($sPkg, %hKey) = @_;
54 282 my $oThis = {};
55 282 bless $oThis;
56 282 return $oThis;
57 }
58  
59 #------------------------------------------------------------------------------
60 # TextFmt (for Spreadsheet::XLSX::Fmt2007)
61 #------------------------------------------------------------------------------
62 1194 ▶sub TextFmt {
Subroutine TextFmt: called CC=3 SCAR=14.2
Pod undocumented
63 1194 my ($oThis, $sTxt, $sCode) = @_;
64 1194 ▶ return $sTxt if ((!defined($sCode)) || ($sCode eq '_native_'));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $sCode or $sCode eq "_native_" 1194 0 1194
Condition33%1/3
not defined $sCode or $sCode eq "_native_"
l!l&&r!l&&!r
119400
MC/DC0%0/2
not defined $sCode or $sCode eq "_native_"
not defined $sCode $sCode eq "_native_"
Truth table33%1/3
not(A) or B
A= not defined $sCodeB= $sCode eq "_native_"
ABresult
1X1
011
000
65 0 return pack('U*', unpack('n*', $sTxt));
66 }
67  
68 #------------------------------------------------------------------------------
69 # FmtStringDef (for Spreadsheet::XLSX::Fmt2007)
70 #------------------------------------------------------------------------------
71 76 ▶sub FmtStringDef {
Subroutine FmtStringDef: called CC=4 SCAR=15.9
Pod undocumented
72 76 my ($oThis, $iFmtIdx, $oBook, $rhFmt) = @_;
73 76 my $sFmtStr = $oBook->{FormatStr}->{$iFmtIdx};
74  
75 76 ▶ if (!(defined($sFmtStr)) && defined($rhFmt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $sFmtStr and defined $rhFmt) 0 76 76
Condition33%1/3
not defined $sFmtStr and defined $rhFmt
!ll&&!rl&&r
0760
MC/DC0%0/2
not defined $sFmtStr and defined $rhFmt
not defined $sFmtStr defined $rhFmt
Truth table33%1/3
not(A) and B
A= not defined $sFmtStrB= defined $rhFmt
ABresult
0X0
100
111
76 0 $sFmtStr = $rhFmt->{$iFmtIdx};
77 }
78 76 ▶ $sFmtStr = $hFmtDefault{$iFmtIdx} unless ($sFmtStr);
Branch: 1 branch
BranchTrueFalseTotal
unless $sFmtStr 76 0 76
79 76 return $sFmtStr;
80 }
81  
82 #------------------------------------------------------------------------------
83 # FmtString (for Spreadsheet::XLSX::Fmt2007)
84 #------------------------------------------------------------------------------
85 2256 ▶sub FmtString {
Subroutine FmtString: called CC=10 SCAR=24.3
Pod undocumented
86 2256 my ($oThis, $oCell, $oBook) = @_;
87  
88 2256 my $sFmtStr; # = $oThis->FmtStringDef(
89  
90 # $oBook->{Format}[$oCell->{FormatNo}]->{FmtIdx}, $oBook);
91  
92 # Check for formula error before evaluating format
93 2256 ▶ return '@' if (defined($oCell->{Val}) && $oCell->{Val} =~ m/^#/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $oCell->{"Val"} and $oCell->{"Val"} =~ /^#/ 0 2256 2256
Condition66%2/3
defined $oCell->{"Val"} and $oCell->{"Val"} =~ /^#/
!ll&&!rl&&r
422520
MC/DC0%0/2
defined $oCell->{"Val"} and $oCell->{"Val"} =~ /^#/
defined $oCell->{"Val"} $oCell->{"Val"} =~ /^#/
Truth table66%2/3
A and B
A= defined $oCell->{"Val"}B= $oCell->{"Val"} =~ /^#/
ABresult
0X0
100
111
94
95 2256 ▶ unless (defined($sFmtStr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sFmtStr) 2256 0 2256
96 2256 ▶ if ($oCell->{Type} eq 'Numeric') {
Branch: 2 branches
BranchTrueFalseTotal
if ($oCell->{'Type'} eq 'Numeric') { } 967 1289 2256
elsif ($oCell->{'Type'} eq 'Date') { } 64 1225 1289
97 967 ▶ if ($oCell->{Format}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($oCell->{'Format'}) { } 655 312 967
elsif (int $oCell->{'Val'} != $oCell->{'Val'}) { } 83 229 312
98 655 $sFmtStr = $oCell->{Format};
99 } elsif (int($oCell->{Val}) != $oCell->{Val}) {
100 83 $sFmtStr = '0.00';
101 } else {
102 229 $sFmtStr = '0';
103 }
104 } elsif ($oCell->{Type} eq 'Date') {
105 64 ▶ if ($oCell->{Format}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($oCell->{'Format'}) { } 64 0 64
elsif (int $oCell->{'Val'} <= 0) { } 0 0 0
106 64 $sFmtStr = $oCell->{Format};
107 } elsif (int($oCell->{Val}) <= 0) {
108 0 $sFmtStr = 'h:mm:ss';
109 } else {
110 0 $sFmtStr = 'm-d-yy';
111 }
112 } else {
113 1225 $sFmtStr = '@';
114 }
115 }
116 2256 return $sFmtStr;
117 }
118  
119 #------------------------------------------------------------------------------
120 # ValFmt (for Spreadsheet::XLSX::Fmt2007)
121 #------------------------------------------------------------------------------
122 2256 ▶sub ValFmt {
Subroutine ValFmt: called CC=4 SCAR=13.9
Pod undocumented
123 2256 my ($oThis, $oCell, $oBook) = @_;
124  
125 2256 my ($Dt, $Flg1904);
126  
127 2256 ▶ if ($oCell->{Type} eq 'Text') {
Branch: 1 branch
BranchTrueFalseTotal
if ($oCell->{'Type'} eq 'Text') { } 1225 1031 2256
128 1225 ▶ $Dt = ((defined $oCell->{Val}) && ($oCell->{Val} ne '')) ? $oThis->TextFmt($oCell->{Val}, $oCell->{Code}) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $oCell->{'Val'} && $oCell->{'Val'} ne '' ? : 1194 31 1225
Condition100%3/3
defined $oCell->{"Val"} and $oCell->{"Val"} ne ""
!ll&&!rl&&r
4271194
MC/DC100%2/2
defined $oCell->{"Val"} and $oCell->{"Val"} ne ""
defined $oCell->{"Val"} $oCell->{"Val"} ne ""
Truth table100%3/3
A and B
A= defined $oCell->{"Val"}B= $oCell->{"Val"} ne ""
ABresult
0X0
100
111
129 } else {
130 1031 $Dt = $oCell->{Val};
131 }
132 2256 $Flg1904 = $oBook->{Flg1904};
133 2256 my $sFmtStr = $oThis->FmtString($oCell, $oBook);
134 2256 return ExcelFmt($sFmtStr, $Dt, $Flg1904, $oCell->{Type});
135 }
136  
137 #------------------------------------------------------------------------------
138 # ChkType (for Spreadsheet::XLSX::Fmt2007)
139 #------------------------------------------------------------------------------
140 0 ▶sub ChkType {
Subroutine ChkType: not called CC=6 SCAR=37.4
Pod undocumented
141 0 my ($oPkg, $iNumeric, $iFmtIdx) = @_;
142 0 ▶ if ($iNumeric) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iNumeric) { } 0 0 0
143 0 ▶ if ( (($iFmtIdx >= 0x0E) && ($iFmtIdx <= 0x16))
Branch: 1 branch
BranchTrueFalseTotal
if ($iFmtIdx >= 14 and $iFmtIdx <= 22 or $iFmtIdx >= 45 and $iFmtIdx <= 47) { } 0 0 0
Condition0%0/9
$iFmtIdx >= 14 and $iFmtIdx <= 22 or $iFmtIdx >= 45 and $iFmtIdx <= 47
l!l&&r!l&&!r
000
$iFmtIdx >= 14 and $iFmtIdx <= 22
!ll&&!rl&&r
000
$iFmtIdx >= 45 and $iFmtIdx <= 47
!ll&&!rl&&r
000
MC/DC0%0/4
$iFmtIdx >= 14 and $iFmtIdx <= 22 or $iFmtIdx >= 45 and $iFmtIdx <= 47
$iFmtIdx >= 14 $iFmtIdx <= 22 $iFmtIdx >= 45 $iFmtIdx <= 47
Truth table0%0/7
A and B or C and D
A= $iFmtIdx >= 14B= $iFmtIdx <= 22C= $iFmtIdx >= 45D= $iFmtIdx <= 47
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
144 || (($iFmtIdx >= 0x2D) && ($iFmtIdx <= 0x2F))) {
145 0 return "Date";
146 } else {
147 0 return "Numeric";
148 }
149 } else {
150 0 return "Text";
151 }
152 }
153 26 1;
154  
155 __END__
« XLSX.pm ↑ Summary