line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::StructuredOutput::Styles; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
33
|
use 5.00503; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
53
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
300
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
9
|
use Carp qw(croak); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
77
|
|
11
|
1
|
|
|
1
|
|
8
|
use Text::CSV_XS; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1606
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# This allows declaration use test1 ':all'; |
18
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
19
|
|
|
|
|
|
|
# will save memory. |
20
|
|
|
|
|
|
|
%EXPORT_TAGS = ( 'all' => [ qw( |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
) ] ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
@EXPORT = qw( |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%03d", q$Revision: 1.8 $ =~ /(\d+)/g; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Preloaded methods go here. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub addstyle |
35
|
|
|
|
|
|
|
{ |
36
|
3
|
|
|
3
|
0
|
6
|
my $proto = shift; |
37
|
3
|
|
33
|
|
|
15
|
my $class = ref($proto) || $proto; |
38
|
3
|
|
|
|
|
6
|
my $attr = shift; |
39
|
|
|
|
|
|
|
|
40
|
3
|
|
|
|
|
4
|
my $self; |
41
|
3
|
|
50
|
|
|
19
|
$self->{format} = $attr->{format} || 'html'; |
42
|
3
|
|
|
|
|
6
|
$self->{wbformat} = $attr->{wbformat}; |
43
|
3
|
|
|
|
|
7
|
$self->{wb} = $attr->{wb}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# make our new object |
46
|
3
|
|
|
|
|
12
|
bless $self, $class; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
sub modify |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
0
|
|
0
|
0
|
0
|
ref(my $self = shift) or croak "instance variable needed"; |
51
|
0
|
|
|
|
|
0
|
my $info = shift; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
my %allowed_formats = ( |
54
|
|
|
|
|
|
|
font => 1, |
55
|
|
|
|
|
|
|
size => 1, |
56
|
|
|
|
|
|
|
color => 1, |
57
|
|
|
|
|
|
|
bold => 1, |
58
|
|
|
|
|
|
|
italic => 1, |
59
|
|
|
|
|
|
|
underline => 1, |
60
|
|
|
|
|
|
|
num_format => 1, |
61
|
|
|
|
|
|
|
align => 1, |
62
|
|
|
|
|
|
|
valign => 1, |
63
|
|
|
|
|
|
|
text_wrap => 1, |
64
|
|
|
|
|
|
|
bg_color => 1, |
65
|
|
|
|
|
|
|
border => 1, |
66
|
|
|
|
|
|
|
num_format => 1, |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# do bool's |
70
|
0
|
0
|
|
|
|
0
|
if (defined($info->{bold})) { |
71
|
0
|
0
|
|
|
|
0
|
my $bold = $info->{bold} ? 1 : 0; |
72
|
0
|
|
|
|
|
0
|
$self->{attr}{bold} = $bold; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
0
|
|
|
|
0
|
if (defined($info->{italic})) { |
75
|
0
|
0
|
|
|
|
0
|
my $italic = $info->{italic} ? 1 : 0; |
76
|
0
|
|
|
|
|
0
|
$self->{attr}{italic} = $italic; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
0
|
|
|
|
0
|
if (defined($info->{color})) |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
0
|
|
|
|
0
|
if ($info->{color} =~ /^(\d+)(#......)/) |
81
|
|
|
|
|
|
|
{ # got an indexed color |
82
|
0
|
|
|
|
|
0
|
my $index = $1; |
83
|
0
|
|
|
|
|
0
|
my $hex = $2; |
84
|
0
|
0
|
|
|
|
0
|
if ($self->{format} eq 'xls') |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
0
|
$self->{wb}->set_custom_color($index,$hex); |
87
|
0
|
|
|
|
|
0
|
$info->{color} = $index; |
88
|
|
|
|
|
|
|
} else { |
89
|
0
|
|
|
|
|
0
|
$info->{color} = $hex; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} else { |
92
|
|
|
|
|
|
|
# assume we got a word like 'white' |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
0
|
0
|
|
|
|
0
|
if (defined($info->{bg_color})) |
96
|
|
|
|
|
|
|
{ |
97
|
0
|
0
|
|
|
|
0
|
if ($info->{bg_color} =~ /^(\d+)(#......)/) |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
|
|
0
|
my $index = $1; |
100
|
0
|
|
|
|
|
0
|
my $hex = $2; |
101
|
0
|
0
|
|
|
|
0
|
if ($self->{format} eq 'xls') |
102
|
|
|
|
|
|
|
{ |
103
|
0
|
|
|
|
|
0
|
$self->{wb}->set_custom_color($index,$hex); |
104
|
0
|
|
|
|
|
0
|
$info->{bg_color} = $index; |
105
|
|
|
|
|
|
|
} else { |
106
|
0
|
|
|
|
|
0
|
$info->{bg_color} = $hex; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} else { |
109
|
|
|
|
|
|
|
# assume we got a word like 'white' |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
0
|
|
|
|
|
0
|
foreach my $key (keys %{$info}) |
|
0
|
|
|
|
|
0
|
|
113
|
|
|
|
|
|
|
{ |
114
|
0
|
0
|
|
|
|
0
|
$self->{attr}{$key} = $info->{$key} if $allowed_formats{$key}; |
115
|
|
|
|
|
|
|
} |
116
|
0
|
0
|
|
|
|
0
|
if ($self->{format} eq 'xls') |
117
|
|
|
|
|
|
|
{ # need to use the xls format object |
118
|
0
|
|
|
|
|
0
|
$self->{wbformat}->set_properties(%{$self->{attr}}); |
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
} |
120
|
0
|
|
|
|
|
0
|
return; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
sub output_style |
123
|
|
|
|
|
|
|
{ |
124
|
12
|
50
|
|
12
|
0
|
39
|
ref(my $self = shift) or croak "instance variable needed"; |
125
|
12
|
|
|
|
|
21
|
my $format = $self->{format}; |
126
|
12
|
100
|
|
|
|
37
|
if ($format eq 'html') |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
127
|
|
|
|
|
|
|
{ |
128
|
6
|
|
|
|
|
10
|
my $data = shift; |
129
|
6
|
|
|
|
|
10
|
my $colspan = shift; |
130
|
6
|
|
|
|
|
7
|
my $rv = " |
|
131
|
6
|
50
|
|
|
|
14
|
$rv .= "COLSPAN=\"$colspan\" " if $colspan; |
132
|
6
|
50
|
|
|
|
20
|
$rv .= "ALIGN=\"$self->{attr}{align}\" " if $self->{attr}{align}; |
133
|
6
|
50
|
|
|
|
17
|
$rv .= "VALIGN=\"$self->{attr}{valign}\" " if $self->{attr}{valign}; |
134
|
6
|
50
|
|
|
|
15
|
$rv .= "BGCOLOR=\"$self->{attr}{bg_color}\" " if $self->{attr}{bg_color}; |
135
|
6
|
50
|
|
|
|
16
|
$rv .= ">{attr}{color}\" " if $self->{attr}{color}; |
136
|
6
|
50
|
|
|
|
16
|
$rv .= ">{attr}{font}\" " if $self->{attr}{font}; |
137
|
6
|
50
|
|
|
|
14
|
$rv .= ">{attr}{font}\" " if $self->{attr}{size}; |
138
|
6
|
50
|
|
|
|
15
|
$rv .= ">{attr}{bold}; |
139
|
6
|
50
|
|
|
|
14
|
$rv .= ">{attr}{italic}; |
140
|
6
|
50
|
|
|
|
15
|
$rv .= ">{attr}{underline}; |
141
|
6
|
|
|
|
|
15
|
$rv .= ">$data<"; |
142
|
6
|
50
|
|
|
|
18
|
$rv .= "/U><" if $self->{attr}{underline}; |
143
|
6
|
50
|
|
|
|
15
|
$rv .= "/I><" if $self->{attr}{italic}; |
144
|
6
|
50
|
|
|
|
14
|
$rv .= "/B><" if $self->{attr}{bold}; |
145
|
6
|
50
|
|
|
|
15
|
$rv .= "/FONT><" if $self->{attr}{size}; |
146
|
6
|
50
|
|
|
|
14
|
$rv .= "/FONT><" if $self->{attr}{font}; |
147
|
6
|
50
|
|
|
|
21
|
$rv .= "/FONT><" if $self->{attr}{color}; |
148
|
6
|
|
|
|
|
10
|
$rv .= "/TD>\n"; |
149
|
6
|
|
|
|
|
35
|
return $rv; |
150
|
|
|
|
|
|
|
} elsif ($format eq 'xls') { |
151
|
6
|
|
|
|
|
29
|
return $self->{wbformat}; |
152
|
|
|
|
|
|
|
} elsif ($format eq 'csv') { |
153
|
0
|
|
|
|
|
|
return; # no style'ing available in this format |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
160
|
|
|
|
|
|
|
__END__ |