blib/lib/Excel/CloneXLSX/Format.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 92.5% 50 / 54 SCAR 22.0
CC
9
Cov
92%
translate_xlsx_format
9.1
BEGIN
1.0
BEGIN
1.0
CRAP 9.0
↑ Summary Build »
1 package Excel::CloneXLSX::Format;
2  
3 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = "0.02";
8  
9 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 our @EXPORT_OK = qw(translate_xlsx_format);
11  
12 sub translate_xlsx_format {
13 1 ▶ my ($old_fmt) = @_;
Subroutine translate_xlsx_format: called CC=9 SCAR=22.1
Pod documented
14 1 ▶ return {} unless (defined $old_fmt);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old_fmt 0 1 1
15  
16 # font
17 1 my $old_font = $old_fmt->{Font};
18 my %new_fmt = (
19 font => $old_font->{Name},
20 size => $old_font->{Height},
21 color => $old_font->{Color},
22 bold => $old_font->{Bold},
23 italic => $old_font->{Italic},
24 underline => $old_font->{UnderlineStyle},
25 font_strikeout => $old_font->{Strikeout},
26 font_script => $old_font->{Super},
27 1 );
28  
29 # shading
30 1 my $old_shading = $old_fmt->{Fill};
31 1 my @shading_fields = qw(pattern fg_color bg_color);
32 1 for my $idx (0..$#shading_fields) {
33 3 ▶ $new_fmt{ $shading_fields[$idx] } = $old_shading->[$idx]
Branch: 1 branch
BranchTrueFalseTotal
if defined $old_shading->[$idx] 1 2 3
34 if (defined $old_shading->[$idx]);
35 }
36  
37 # if pattern is 'solid', Excel swaps fgColor and bgColor. This unswaps.
38 1 ▶ if ($new_fmt{pattern} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_fmt{"pattern"} == 1) 0 1 1
39 0 @new_fmt{qw(bg_color fg_color)} = @new_fmt{qw(fg_color bg_color)};
40 }
41  
42 # alignment
43 # halign numbers match up, valign numbers are off by one
44 1 my ($old_halign, $old_valign) = @{$old_fmt}{qw(AlignH AlignV)};
45 1 $new_fmt{text_h_align} = $old_halign;
46 1 ▶ $new_fmt{text_v_align} = defined($old_valign) ? $old_valign+1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $old_valign ? : 1 0 1
47  
48 # borders
49 1 my $old_border_style = $old_fmt->{BdrStyle};
50 1 my $old_border_color = $old_fmt->{BdrColor};
51 1 my @sides = qw(left right top bottom);
52 1 for my $idx (0..$#sides) {
53 4 my $side = $sides[$idx];
54 4 ▶ $new_fmt{$side} = $old_border_style->[$idx] if ($old_border_style->[$idx]);
Branch: 1 branch
BranchTrueFalseTotal
if $old_border_style->[$idx] 1 3 4
55 4 ▶ $new_fmt{"${side}_color"} = $old_border_color->[$idx] if ($old_border_color->[$idx]);
Branch: 1 branch
BranchTrueFalseTotal
if $old_border_color->[$idx] 1 3 4
56 }
57  
58 1 return \%new_fmt;
59 }
60  
61  
62  
63 2 1;
64 __END__
↑ Summary Build »