XLSX/Fmt2007.pm

filter: Statementstmt 72.2% 39 / 54 Branchbran 50.0% 15 / 30 Conditioncond 11.1% 2 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 6 totaltotal 49.6% 63 / 127 CC 22 SCAR 27.2
CC
22
Cov
55%
ChkType
42.0
FmtStringDef
20.0
FmtString
9.9
CRAP 15.1
« XLSX.pm ↑ Summary
1 package Spreadsheet::XLSX::Fmt2007;
2 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use Spreadsheet::XLSX::Utility2007 qw(ExcelFmt);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 our $VERSION = '0.20'; #
7  
8 12 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 80 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
53 80 my ($sPkg, %hKey) = @_;
54 80 my $oThis = {};
55 80 bless $oThis;
56 80 return $oThis;
57 }
58  
59 #------------------------------------------------------------------------------
60 # TextFmt (for Spreadsheet::XLSX::Fmt2007)
61 #------------------------------------------------------------------------------
62 836 ▶sub TextFmt {
Subroutine TextFmt: called CC=3 SCAR=14.2
Pod undocumented
63 836 my ($oThis, $sTxt, $sCode) = @_;
64 836 ▶ return $sTxt if ((!defined($sCode)) || ($sCode eq '_native_'));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $sCode or $sCode eq "_native_" 836 0 836
Condition33%1/3
not defined $sCode or $sCode eq "_native_"
l!l&&r!l&&!r
83600
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 0 ▶sub FmtStringDef {
Subroutine FmtStringDef: not called CC=4 SCAR=30.0
Pod undocumented
72 0 my ($oThis, $iFmtIdx, $oBook, $rhFmt) = @_;
73 0 my $sFmtStr = $oBook->{FormatStr}->{$iFmtIdx};
74  
75 0 ▶ if (!(defined($sFmtStr)) && defined($rhFmt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $sFmtStr and defined $rhFmt) 0 0 0
Condition0%0/3
not defined $sFmtStr and defined $rhFmt
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $sFmtStr and defined $rhFmt
not defined $sFmtStr defined $rhFmt
Truth table0%0/3
not(A) and B
A= not defined $sFmtStrB= defined $rhFmt
ABresult
0X0
100
111
76 0 $sFmtStr = $rhFmt->{$iFmtIdx};
77 }
78 0 ▶ $sFmtStr = $hFmtDefault{$iFmtIdx} unless ($sFmtStr);
Branch: 1 branch
BranchTrueFalseTotal
unless $sFmtStr 0 0 0
79 0 return $sFmtStr;
80 }
81  
82 #------------------------------------------------------------------------------
83 # FmtString (for Spreadsheet::XLSX::Fmt2007)
84 #------------------------------------------------------------------------------
85 1653 ▶sub FmtString {
Subroutine FmtString: called CC=9 SCAR=23.0
Pod undocumented
86 1653 my ($oThis, $oCell, $oBook) = @_;
87  
88 1653 my $sFmtStr; # = $oThis->FmtStringDef(
89  
90 # $oBook->{Format}[$oCell->{FormatNo}]->{FmtIdx}, $oBook);
91  
92 # Check for formula error before evaluating format
93 1653 ▶ return '@' if ( $oCell->{Val} =~ m/^#/ );
Branch: 1 branch
BranchTrueFalseTotal
if $oCell->{"Val"} =~ /^#/ 0 1653 1653
94
95 1653 ▶ unless (defined($sFmtStr)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sFmtStr) 1653 0 1653
96 1653 ▶ if ($oCell->{Type} eq 'Numeric') {
Branch: 2 branches
BranchTrueFalseTotal
if ($oCell->{'Type'} eq 'Numeric') { } 813 840 1653
elsif ($oCell->{'Type'} eq 'Date') { } 4 836 840
97 813 ▶ if ($oCell->{Format}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($oCell->{'Format'}) { } 397 416 813
elsif (int $oCell->{'Val'} != $oCell->{'Val'}) { } 242 174 416
98 397 $sFmtStr = $oCell->{Format};
99 } elsif (int($oCell->{Val}) != $oCell->{Val}) {
100 242 $sFmtStr = '0.00';
101 } else {
102 174 $sFmtStr = '0';
103 }
104 } elsif ($oCell->{Type} eq 'Date') {
105 4 ▶ if ($oCell->{Format}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($oCell->{'Format'}) { } 4 0 4
elsif (int $oCell->{'Val'} <= 0) { } 0 0 0
106 4 $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 836 $sFmtStr = '@';
114 }
115 }
116 1653 return $sFmtStr;
117 }
118  
119 #------------------------------------------------------------------------------
120 # ValFmt (for Spreadsheet::XLSX::Fmt2007)
121 #------------------------------------------------------------------------------
122 1653 ▶sub ValFmt {
Subroutine ValFmt: called CC=4 SCAR=14.2
Pod undocumented
123 1653 my ($oThis, $oCell, $oBook) = @_;
124  
125 1653 my ($Dt, $iFmtIdx, $iNumeric, $Flg1904);
126  
127 1653 ▶ if ($oCell->{Type} eq 'Text') {
Branch: 1 branch
BranchTrueFalseTotal
if ($oCell->{'Type'} eq 'Text') { } 836 817 1653
128 836 ▶ $Dt = ((defined $oCell->{Val}) && ($oCell->{Val} ne '')) ? $oThis->TextFmt($oCell->{Val}, $oCell->{Code}) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $oCell->{'Val'} && $oCell->{'Val'} ne '' ? : 836 0 836
Condition33%1/3
defined $oCell->{"Val"} and $oCell->{"Val"} ne ""
!ll&&!rl&&r
00836
MC/DC0%0/2
defined $oCell->{"Val"} and $oCell->{"Val"} ne ""
defined $oCell->{"Val"} $oCell->{"Val"} ne ""
Truth table33%1/3
A and B
A= defined $oCell->{"Val"}B= $oCell->{"Val"} ne ""
ABresult
0X0
100
111
129 } else {
130 817 $Dt = $oCell->{Val};
131 }
132 1653 $Flg1904 = $oBook->{Flg1904};
133 1653 my $sFmtStr = $oThis->FmtString($oCell, $oBook);
134 1653 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 12 1;
154  
155 __END__
« XLSX.pm ↑ Summary