File Coverage

blib/lib/Excel/Writer/XLSX/Package/Theme.pm
Criterion Covered Total %
statement 37 37 100.0
branch 1 2 50.0
condition n/a
subroutine 11 11 100.0
pod 0 1 0.0
total 49 51 96.0


line stmt bran cond sub pod time code
1             package Excel::Writer::XLSX::Package::Theme;
2              
3             ###############################################################################
4             #
5             # Theme - A class for writing the Excel XLSX Theme file.
6             #
7             # Used in conjunction with Excel::Writer::XLSX
8             #
9             # Copyright 2000-2019, John McNamara, jmcnamara@cpan.org
10             #
11             # Documentation after __END__
12             #
13              
14             # perltidy with the following options: -mbl=2 -pt=0 -nola
15              
16              
17             ###############################################################################
18             #
19             # NOTE: This class doesn't try to create the Excel theme1.xml programmatically.
20             # Instead it just writes a stored default theme. This is mainly to
21             # facilitate easier comparisons during testing. The theme1.xml file
22             # isn't actually required.
23              
24 1040     1040   17700 use 5.008002;
  1040         4964  
25 1040     1040   5581 use strict;
  1040         5542  
  1040         21734  
26 1040     1040   5166 use warnings;
  1040         5626  
  1040         26722  
27 1040     1040   6613 use Exporter;
  1040         3418  
  1040         36907  
28 1040     1040   7298 use Carp;
  1040         3493  
  1040         59827  
29 1040     1040   8309 use IO::File;
  1040         4983  
  1040         148369  
30 1040     1040   617568 use utf8;
  1040         15177  
  1040         6699  
31              
32             our @ISA = qw(Exporter);
33             our $VERSION = '1.03';
34              
35              
36             ###############################################################################
37             #
38             # Public and private API methods.
39             #
40             ###############################################################################
41              
42              
43             ###############################################################################
44             #
45             # new()
46             #
47             # Constructor.
48             #
49             sub new {
50              
51 809     809 0 2196 my $class = shift;
52              
53 809         2127 my $self = {};
54              
55 809         2313 bless $self, $class;
56              
57 809         2400 return $self;
58             }
59              
60              
61             ###############################################################################
62             #
63             # _assemble_xml_file()
64             #
65             # Assemble and write the XML file.
66             #
67             sub _assemble_xml_file {
68              
69 809     809   2103 my $self = shift;
70              
71 809         3575 $self->_write_theme_file();
72             }
73              
74              
75             ###############################################################################
76             #
77             # _set_xml_writer()
78             #
79             # Set the filehandle only. This class doesn't use a real XML writer class.
80             #
81             sub _set_xml_writer {
82              
83 809     809   10781 my $self = shift;
84 809         1909 my $filename = shift;
85              
86 809         6112 my $fh = IO::File->new( $filename, 'w' );
87 809 50       99554 croak "Couldn't open file $filename for writing.\n" unless $fh;
88              
89 809         4676 binmode $fh, ':utf8';
90              
91 809         8445 $self->{_fh} = $fh;
92             }
93              
94              
95             ###############################################################################
96             #
97             # Internal methods.
98             #
99             ###############################################################################
100              
101             # Sparklines styles. Used by the Worksheet class.
102             our @spark_styles = (
103             { # 0
104             series => { _theme => "4", _tint => "-0.499984740745262" },
105             negative => { _theme => "5" },
106             markers => { _theme => "4", _tint => "-0.499984740745262" },
107             first => { _theme => "4", _tint => "0.39997558519241921" },
108             last => { _theme => "4", _tint => "0.39997558519241921" },
109             high => { _theme => "4" },
110             low => { _theme => "4" },
111             },
112             { # 1
113             series => { _theme => "4", _tint => "-0.499984740745262" },
114             negative => { _theme => "5" },
115             markers => { _theme => "4", _tint => "-0.499984740745262" },
116             first => { _theme => "4", _tint => "0.39997558519241921" },
117             last => { _theme => "4", _tint => "0.39997558519241921" },
118             high => { _theme => "4" },
119             low => { _theme => "4" },
120             },
121             { # 2
122             series => { _theme => "5", _tint => "-0.499984740745262" },
123             negative => { _theme => "6" },
124             markers => { _theme => "5", _tint => "-0.499984740745262" },
125             first => { _theme => "5", _tint => "0.39997558519241921" },
126             last => { _theme => "5", _tint => "0.39997558519241921" },
127             high => { _theme => "5" },
128             low => { _theme => "5" },
129             },
130             { # 3
131             series => { _theme => "6", _tint => "-0.499984740745262" },
132             negative => { _theme => "7" },
133             markers => { _theme => "6", _tint => "-0.499984740745262" },
134             first => { _theme => "6", _tint => "0.39997558519241921" },
135             last => { _theme => "6", _tint => "0.39997558519241921" },
136             high => { _theme => "6" },
137             low => { _theme => "6" },
138             },
139             { # 4
140             series => { _theme => "7", _tint => "-0.499984740745262" },
141             negative => { _theme => "8" },
142             markers => { _theme => "7", _tint => "-0.499984740745262" },
143             first => { _theme => "7", _tint => "0.39997558519241921" },
144             last => { _theme => "7", _tint => "0.39997558519241921" },
145             high => { _theme => "7" },
146             low => { _theme => "7" },
147             },
148             { # 5
149             series => { _theme => "8", _tint => "-0.499984740745262" },
150             negative => { _theme => "9" },
151             markers => { _theme => "8", _tint => "-0.499984740745262" },
152             first => { _theme => "8", _tint => "0.39997558519241921" },
153             last => { _theme => "8", _tint => "0.39997558519241921" },
154             high => { _theme => "8" },
155             low => { _theme => "8" },
156             },
157             { # 6
158             series => { _theme => "9", _tint => "-0.499984740745262" },
159             negative => { _theme => "4" },
160             markers => { _theme => "9", _tint => "-0.499984740745262" },
161             first => { _theme => "9", _tint => "0.39997558519241921" },
162             last => { _theme => "9", _tint => "0.39997558519241921" },
163             high => { _theme => "9" },
164             low => { _theme => "9" },
165             },
166             { # 7
167             series => { _theme => "4", _tint => "-0.249977111117893" },
168             negative => { _theme => "5" },
169             markers => { _theme => "5", _tint => "-0.249977111117893" },
170             first => { _theme => "5", _tint => "-0.249977111117893" },
171             last => { _theme => "5", _tint => "-0.249977111117893" },
172             high => { _theme => "5", _tint => "-0.249977111117893" },
173             low => { _theme => "5", _tint => "-0.249977111117893" },
174             },
175             { # 8
176             series => { _theme => "5", _tint => "-0.249977111117893" },
177             negative => { _theme => "6" },
178             markers => { _theme => "6", _tint => "-0.249977111117893" },
179             first => { _theme => "6", _tint => "-0.249977111117893" },
180             last => { _theme => "6", _tint => "-0.249977111117893" },
181             high => { _theme => "6", _tint => "-0.249977111117893" },
182             low => { _theme => "6", _tint => "-0.249977111117893" },
183             },
184             { # 9
185             series => { _theme => "6", _tint => "-0.249977111117893" },
186             negative => { _theme => "7" },
187             markers => { _theme => "7", _tint => "-0.249977111117893" },
188             first => { _theme => "7", _tint => "-0.249977111117893" },
189             last => { _theme => "7", _tint => "-0.249977111117893" },
190             high => { _theme => "7", _tint => "-0.249977111117893" },
191             low => { _theme => "7", _tint => "-0.249977111117893" },
192             },
193             { # 10
194             series => { _theme => "7", _tint => "-0.249977111117893" },
195             negative => { _theme => "8" },
196             markers => { _theme => "8", _tint => "-0.249977111117893" },
197             first => { _theme => "8", _tint => "-0.249977111117893" },
198             last => { _theme => "8", _tint => "-0.249977111117893" },
199             high => { _theme => "8", _tint => "-0.249977111117893" },
200             low => { _theme => "8", _tint => "-0.249977111117893" },
201             },
202             { # 11
203             series => { _theme => "8", _tint => "-0.249977111117893" },
204             negative => { _theme => "9" },
205             markers => { _theme => "9", _tint => "-0.249977111117893" },
206             first => { _theme => "9", _tint => "-0.249977111117893" },
207             last => { _theme => "9", _tint => "-0.249977111117893" },
208             high => { _theme => "9", _tint => "-0.249977111117893" },
209             low => { _theme => "9", _tint => "-0.249977111117893" },
210             },
211             { # 12
212             series => { _theme => "9", _tint => "-0.249977111117893" },
213             negative => { _theme => "4" },
214             markers => { _theme => "4", _tint => "-0.249977111117893" },
215             first => { _theme => "4", _tint => "-0.249977111117893" },
216             last => { _theme => "4", _tint => "-0.249977111117893" },
217             high => { _theme => "4", _tint => "-0.249977111117893" },
218             low => { _theme => "4", _tint => "-0.249977111117893" },
219             },
220             { # 13
221             series => { _theme => "4" },
222             negative => { _theme => "5" },
223             markers => { _theme => "4", _tint => "-0.249977111117893" },
224             first => { _theme => "4", _tint => "-0.249977111117893" },
225             last => { _theme => "4", _tint => "-0.249977111117893" },
226             high => { _theme => "4", _tint => "-0.249977111117893" },
227             low => { _theme => "4", _tint => "-0.249977111117893" },
228             },
229             { # 14
230             series => { _theme => "5" },
231             negative => { _theme => "6" },
232             markers => { _theme => "5", _tint => "-0.249977111117893" },
233             first => { _theme => "5", _tint => "-0.249977111117893" },
234             last => { _theme => "5", _tint => "-0.249977111117893" },
235             high => { _theme => "5", _tint => "-0.249977111117893" },
236             low => { _theme => "5", _tint => "-0.249977111117893" },
237             },
238             { # 15
239             series => { _theme => "6" },
240             negative => { _theme => "7" },
241             markers => { _theme => "6", _tint => "-0.249977111117893" },
242             first => { _theme => "6", _tint => "-0.249977111117893" },
243             last => { _theme => "6", _tint => "-0.249977111117893" },
244             high => { _theme => "6", _tint => "-0.249977111117893" },
245             low => { _theme => "6", _tint => "-0.249977111117893" },
246             },
247             { # 16
248             series => { _theme => "7" },
249             negative => { _theme => "8" },
250             markers => { _theme => "7", _tint => "-0.249977111117893" },
251             first => { _theme => "7", _tint => "-0.249977111117893" },
252             last => { _theme => "7", _tint => "-0.249977111117893" },
253             high => { _theme => "7", _tint => "-0.249977111117893" },
254             low => { _theme => "7", _tint => "-0.249977111117893" },
255             },
256             { # 17
257             series => { _theme => "8" },
258             negative => { _theme => "9" },
259             markers => { _theme => "8", _tint => "-0.249977111117893" },
260             first => { _theme => "8", _tint => "-0.249977111117893" },
261             last => { _theme => "8", _tint => "-0.249977111117893" },
262             high => { _theme => "8", _tint => "-0.249977111117893" },
263             low => { _theme => "8", _tint => "-0.249977111117893" },
264             },
265             { # 18
266             series => { _theme => "9" },
267             negative => { _theme => "4" },
268             markers => { _theme => "9", _tint => "-0.249977111117893" },
269             first => { _theme => "9", _tint => "-0.249977111117893" },
270             last => { _theme => "9", _tint => "-0.249977111117893" },
271             high => { _theme => "9", _tint => "-0.249977111117893" },
272             low => { _theme => "9", _tint => "-0.249977111117893" },
273             },
274             { # 19
275             series => { _theme => "4", _tint => "0.39997558519241921" },
276             negative => { _theme => "0", _tint => "-0.499984740745262" },
277             markers => { _theme => "4", _tint => "0.79998168889431442" },
278             first => { _theme => "4", _tint => "-0.249977111117893" },
279             last => { _theme => "4", _tint => "-0.249977111117893" },
280             high => { _theme => "4", _tint => "-0.499984740745262" },
281             low => { _theme => "4", _tint => "-0.499984740745262" },
282             },
283             { # 20
284             series => { _theme => "5", _tint => "0.39997558519241921" },
285             negative => { _theme => "0", _tint => "-0.499984740745262" },
286             markers => { _theme => "5", _tint => "0.79998168889431442" },
287             first => { _theme => "5", _tint => "-0.249977111117893" },
288             last => { _theme => "5", _tint => "-0.249977111117893" },
289             high => { _theme => "5", _tint => "-0.499984740745262" },
290             low => { _theme => "5", _tint => "-0.499984740745262" },
291             },
292             { # 21
293             series => { _theme => "6", _tint => "0.39997558519241921" },
294             negative => { _theme => "0", _tint => "-0.499984740745262" },
295             markers => { _theme => "6", _tint => "0.79998168889431442" },
296             first => { _theme => "6", _tint => "-0.249977111117893" },
297             last => { _theme => "6", _tint => "-0.249977111117893" },
298             high => { _theme => "6", _tint => "-0.499984740745262" },
299             low => { _theme => "6", _tint => "-0.499984740745262" },
300             },
301             { # 22
302             series => { _theme => "7", _tint => "0.39997558519241921" },
303             negative => { _theme => "0", _tint => "-0.499984740745262" },
304             markers => { _theme => "7", _tint => "0.79998168889431442" },
305             first => { _theme => "7", _tint => "-0.249977111117893" },
306             last => { _theme => "7", _tint => "-0.249977111117893" },
307             high => { _theme => "7", _tint => "-0.499984740745262" },
308             low => { _theme => "7", _tint => "-0.499984740745262" },
309             },
310             { # 23
311             series => { _theme => "8", _tint => "0.39997558519241921" },
312             negative => { _theme => "0", _tint => "-0.499984740745262" },
313             markers => { _theme => "8", _tint => "0.79998168889431442" },
314             first => { _theme => "8", _tint => "-0.249977111117893" },
315             last => { _theme => "8", _tint => "-0.249977111117893" },
316             high => { _theme => "8", _tint => "-0.499984740745262" },
317             low => { _theme => "8", _tint => "-0.499984740745262" },
318             },
319             { # 24
320             series => { _theme => "9", _tint => "0.39997558519241921" },
321             negative => { _theme => "0", _tint => "-0.499984740745262" },
322             markers => { _theme => "9", _tint => "0.79998168889431442" },
323             first => { _theme => "9", _tint => "-0.249977111117893" },
324             last => { _theme => "9", _tint => "-0.249977111117893" },
325             high => { _theme => "9", _tint => "-0.499984740745262" },
326             low => { _theme => "9", _tint => "-0.499984740745262" },
327             },
328             { # 25
329             series => { _theme => "1", _tint => "0.499984740745262" },
330             negative => { _theme => "1", _tint => "0.249977111117893" },
331             markers => { _theme => "1", _tint => "0.249977111117893" },
332             first => { _theme => "1", _tint => "0.249977111117893" },
333             last => { _theme => "1", _tint => "0.249977111117893" },
334             high => { _theme => "1", _tint => "0.249977111117893" },
335             low => { _theme => "1", _tint => "0.249977111117893" },
336             },
337             { # 26
338             series => { _theme => "1", _tint => "0.34998626667073579" },
339             negative => { _theme => "0", _tint => "-0.249977111117893" },
340             markers => { _theme => "0", _tint => "-0.249977111117893" },
341             first => { _theme => "0", _tint => "-0.249977111117893" },
342             last => { _theme => "0", _tint => "-0.249977111117893" },
343             high => { _theme => "0", _tint => "-0.249977111117893" },
344             low => { _theme => "0", _tint => "-0.249977111117893" },
345             },
346             { # 27
347             series => { _rgb => "FF323232" },
348             negative => { _rgb => "FFD00000" },
349             markers => { _rgb => "FFD00000" },
350             first => { _rgb => "FFD00000" },
351             last => { _rgb => "FFD00000" },
352             high => { _rgb => "FFD00000" },
353             low => { _rgb => "FFD00000" },
354             },
355             { # 28
356             series => { _rgb => "FF000000" },
357             negative => { _rgb => "FF0070C0" },
358             markers => { _rgb => "FF0070C0" },
359             first => { _rgb => "FF0070C0" },
360             last => { _rgb => "FF0070C0" },
361             high => { _rgb => "FF0070C0" },
362             low => { _rgb => "FF0070C0" },
363             },
364             { # 29
365             series => { _rgb => "FF376092" },
366             negative => { _rgb => "FFD00000" },
367             markers => { _rgb => "FFD00000" },
368             first => { _rgb => "FFD00000" },
369             last => { _rgb => "FFD00000" },
370             high => { _rgb => "FFD00000" },
371             low => { _rgb => "FFD00000" },
372             },
373             { # 30
374             series => { _rgb => "FF0070C0" },
375             negative => { _rgb => "FF000000" },
376             markers => { _rgb => "FF000000" },
377             first => { _rgb => "FF000000" },
378             last => { _rgb => "FF000000" },
379             high => { _rgb => "FF000000" },
380             low => { _rgb => "FF000000" },
381             },
382             { # 31
383             series => { _rgb => "FF5F5F5F" },
384             negative => { _rgb => "FFFFB620" },
385             markers => { _rgb => "FFD70077" },
386             first => { _rgb => "FF5687C2" },
387             last => { _rgb => "FF359CEB" },
388             high => { _rgb => "FF56BE79" },
389             low => { _rgb => "FFFF5055" },
390             },
391             { # 32
392             series => { _rgb => "FF5687C2" },
393             negative => { _rgb => "FFFFB620" },
394             markers => { _rgb => "FFD70077" },
395             first => { _rgb => "FF777777" },
396             last => { _rgb => "FF359CEB" },
397             high => { _rgb => "FF56BE79" },
398             low => { _rgb => "FFFF5055" },
399             },
400             { # 33
401             series => { _rgb => "FFC6EFCE" },
402             negative => { _rgb => "FFFFC7CE" },
403             markers => { _rgb => "FF8CADD6" },
404             first => { _rgb => "FFFFDC47" },
405             last => { _rgb => "FFFFEB9C" },
406             high => { _rgb => "FF60D276" },
407             low => { _rgb => "FFFF5367" },
408             },
409             { # 34
410             series => { _rgb => "FF00B050" },
411             negative => { _rgb => "FFFF0000" },
412             markers => { _rgb => "FF0070C0" },
413             first => { _rgb => "FFFFC000" },
414             last => { _rgb => "FFFFC000" },
415             high => { _rgb => "FF00B050" },
416             low => { _rgb => "FFFF0000" },
417             },
418             { # 35
419             series => { _theme => "3" },
420             negative => { _theme => "9" },
421             markers => { _theme => "8" },
422             first => { _theme => "4" },
423             last => { _theme => "5" },
424             high => { _theme => "6" },
425             low => { _theme => "7" },
426             },
427             { # 36
428             series => { _theme => "1" },
429             negative => { _theme => "9" },
430             markers => { _theme => "8" },
431             first => { _theme => "4" },
432             last => { _theme => "5" },
433             high => { _theme => "6" },
434             low => { _theme => "7" },
435             },
436             );
437              
438              
439             ###############################################################################
440             #
441             # XML writing methods.
442             #
443             ###############################################################################
444              
445              
446             ###############################################################################
447             #
448             # _write_theme_file()
449             #
450             # Write a default theme.xml file.
451             #
452             sub _write_theme_file {
453              
454 809     809   1968 my $self = shift;
455 809         2090 my $theme = << 'XML_DATA';
456            
457            
458             XML_DATA
459              
460 809         3029 local $\ = undef; # Protect print from -l on commandline.
461 809         1922 print { $self->{_fh} } $theme;
  809         53022  
462             }
463              
464              
465             1;
466              
467              
468             __END__