ParseExcel/FmtJapan.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 85.7% 12 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 87.8% 65 / 74 CC 10 SCAR 11.6
CC
10
Cov
92%
new
5.3
TextFmt
4.0
CnvNengo
3.0
CRAP 3.2
« ParseExcel/Dump.pm ↑ Summary ParseExcel/SaveParser/Worksheet.pm »
1 package Spreadsheet::ParseExcel::FmtJapan;
2 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 ###############################################################################
5 #
6 # Spreadsheet::ParseExcel::FmtJapan - A class for Cell formats.
7 #
8 # Used in conjunction with Spreadsheet::ParseExcel.
9 #
10 # Copyright (c) 2014 Douglas Wilson
11 # Copyright (c) 2009-2013 John McNamara
12 # Copyright (c) 2006-2008 Gabor Szabo
13 # Copyright (c) 2000-2006 Kawai Takanori
14 #
15 # perltidy with standard settings.
16 #
17 # Documentation after __END__
18 #
19  
20 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 ▶use Encode qw(find_encoding decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use base 'Spreadsheet::ParseExcel::FmtDefault';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 our $VERSION = '0.66';
26  
27 5 my %FormatTable = (
28 0x00 => 'General',
29 0x01 => '0',
30 0x02 => '0.00',
31 0x03 => '#,##0',
32 0x04 => '#,##0.00',
33 0x05 => '(\\#,##0_);(\\#,##0)',
34 0x06 => '(\\#,##0_);[Red](\\#,##0)',
35 0x07 => '(\\#,##0.00_);(\\#,##0.00_)',
36 0x08 => '(\\#,##0.00_);[Red](\\#,##0.00_)',
37 0x09 => '0%',
38 0x0A => '0.00%',
39 0x0B => '0.00E+00',
40 0x0C => '# ?/?',
41 0x0D => '# ??/??',
42  
43 # 0x0E => 'm/d/yy',
44 0x0E => 'yyyy/m/d',
45 0x0F => 'd-mmm-yy',
46 0x10 => 'd-mmm',
47 0x11 => 'mmm-yy',
48 0x12 => 'h:mm AM/PM',
49 0x13 => 'h:mm:ss AM/PM',
50 0x14 => 'h:mm',
51 0x15 => 'h:mm:ss',
52  
53 # 0x16 => 'm/d/yy h:mm',
54 0x16 => 'yyyy/m/d h:mm',
55  
56 #0x17-0x24 -- Differs in Natinal
57 0x1E => 'm/d/yy',
58 0x1F => 'yyyy"年"m"月"d"日"',
59 0x20 => 'h"時"mm"分"',
60 0x21 => 'h"時"mm"分"ss"秒"',
61  
62 #0x17-0x24 -- Differs in Natinal
63 0x25 => '(#,##0_);(#,##0)',
64 0x26 => '(#,##0_);[Red](#,##0)',
65 0x27 => '(#,##0.00);(#,##0.00)',
66 0x28 => '(#,##0.00);[Red](#,##0.00)',
67 0x29 => '_(*#,##0_);_(*(#,##0);_(*"-"_);_(@_)',
68 0x2A => '_(\\*#,##0_);_(\\*(#,##0);_(*"-"_);_(@_)',
69 0x2B => '_(*#,##0.00_);_(*(#,##0.00);_(*"-"??_);_(@_)',
70 0x2C => '_(\\*#,##0.00_);_(\\*(#,##0.00);_(*"-"??_);_(@_)',
71 0x2D => 'mm:ss',
72 0x2E => '[h]:mm:ss',
73 0x2F => 'mm:ss.0',
74 0x30 => '##0.0E+0',
75 0x31 => '@',
76  
77 0x37 => 'yyyy"年"m"月"',
78 0x38 => 'm"月"d"日"',
79 0x39 => 'ge.m.d',
80 0x3A => 'ggge"年"m"月"d"日"',
81 );
82  
83 #------------------------------------------------------------------------------
84 # new (for Spreadsheet::ParseExcel::FmtJapan)
85 #------------------------------------------------------------------------------
86 5 ▶sub new {
Subroutine new: called CC=5 SCAR=16.7
Pod undocumented
87 5 my ( $class, %args ) = @_;
88 5 ▶ my $encoding = $args{Code} || $args{encoding};
Condition100%3/3
$args{'Code'} || $args{'encoding'}
l!l&&r!l&&!r
113
MC/DC100%2/2
$args{'Code'} || $args{'encoding'}
$args{'Code'} $args{'encoding'}
Truth table100%3/3
A || B
A= $args{'Code'}B= $args{'encoding'}
ABresult
1X1
011
000
89 5 my $self = { Code => $encoding };
90 5 ▶ if($encoding){
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding) 2 3 5
91 $self->{encoding} = find_encoding($encoding eq 'sjis' ? 'cp932' : $encoding)
92 2 ▶ or do{
Branch: 2 branches
BranchTrueFalseTotal
$self->{"encoding"} = &find_encoding(scalar($encoding eq "sjis" ? "cp932" : $encoding)) or do { require Carp; Carp::croak("Unknown encoding '${encoding}'") } 2 0 2
$encoding eq 'sjis' ? : 2 0 2
93 0 require Carp;
94 0 Carp::croak(qq{Unknown encoding '$encoding'});
95 };
96 }
97 5 return bless $self, $class;
98 }
99  
100 #------------------------------------------------------------------------------
101 # TextFmt (for Spreadsheet::ParseExcel::FmtJapan)
102 #------------------------------------------------------------------------------
103 250 ▶sub TextFmt {
Subroutine TextFmt: called CC=4 SCAR=13.9
Pod undocumented
104 250 my ( $self, $text, $input_encoding ) = @_;
105 250 ▶ if(!defined $input_encoding){
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $input_encoding) { } 102 148 250
elsif ($input_encoding eq '_native_') { } 80 68 148
106 102 $input_encoding = 'utf8';
107 }
108 elsif($input_encoding eq '_native_'){
109 80 $input_encoding = 'cp932'; # Shift_JIS in Microsoft products
110 }
111 250 $text = decode($input_encoding, $text);
112 250 ▶ return $self->{Code} ? $self->{encoding}->encode($text) : $text;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'Code'} ? : 111 139 250
113 }
114 #------------------------------------------------------------------------------
115 # FmtStringDef (for Spreadsheet::ParseExcel::FmtJapan)
116 #------------------------------------------------------------------------------
117 56 ▶sub FmtStringDef {
Subroutine FmtStringDef: called CC=1 SCAR=0.0
Pod undocumented
118 56 my ( $self, $format_index, $book ) = @_;
119 56 return $self->SUPER::FmtStringDef( $format_index, $book, \%FormatTable );
120 }
121  
122 #------------------------------------------------------------------------------
123 # CnvNengo (for Spreadsheet::ParseExcel::FmtJapan)
124 #------------------------------------------------------------------------------
125  
126 # Convert A.D. into Japanese Nengo (aka Gengo)
127  
128 5 my @Nengo = (
129 {
130 name => '平成', # Heisei
131 abbr_name => 'H',
132  
133 base => 1988,
134 start => 19890108,
135 },
136 {
137 name => '昭和', # Showa
138 abbr_name => 'S',
139  
140 base => 1925,
141 start => 19261225,
142 },
143 {
144 name => '大正', # Taisho
145 abbr_name => 'T',
146  
147 base => 1911,
148 start => 19120730,
149 },
150 {
151 name => '明治', # Meiji
152 abbr_name => 'M',
153  
154 base => 1867,
155 start => 18680908,
156 },
157 );
158  
159 # Usage: CnvNengo(name => @tm) or CnvNeng(abbr_name => @tm)
160 8 ▶sub CnvNengo {
Subroutine CnvNengo: called CC=3 SCAR=11.0
Pod undocumented
161 8 my ( $kind, @tm ) = @_;
162 8 my $year = $tm[5] + 1900;
163 8 my $wk = ($year * 10000) + ($tm[4] * 100) + ($tm[3] * 1);
164 #my $wk = sprintf( '%04d%02d%02d', $year, $tm[4], $tm[3] );
165 8 foreach my $nengo(@Nengo){
166 20 ▶ if( $wk >= $nengo->{start} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($wk >= $nengo->{"start"}) 8 12 20
167 8 return $nengo->{$kind} . ($year - $nengo->{base});
168 }
169 }
170 0 return $year;
171 }
172  
173 5 1;
174  
175 __END__
« ParseExcel/Dump.pm ↑ Summary ParseExcel/SaveParser/Worksheet.pm »