File Coverage

blib/lib/Excel/Writer/XLSX/Package/App.pm
Criterion Covered Total %
statement 117 117 100.0
branch 10 10 100.0
condition 2 2 100.0
subroutine 25 25 100.0
pod 0 1 0.0
total 154 155 99.3


line stmt bran cond sub pod time code
1             package Excel::Writer::XLSX::Package::App;
2              
3             ###############################################################################
4             #
5             # App - A class for writing the Excel XLSX app.xml file.
6             #
7             # Used in conjunction with Excel::Writer::XLSX
8             #
9             # Copyright 2000-2020, 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 1081     1081   18065 use 5.008002;
  1081         5005  
17 1081     1081   6625 use strict;
  1081         3437  
  1081         21883  
18 1081     1081   4784 use warnings;
  1081         3270  
  1081         26557  
19 1081     1081   6091 use Carp;
  1081         3316  
  1081         54696  
20 1081     1081   9568 use Excel::Writer::XLSX::Package::XMLwriter;
  1081         3641  
  1081         1134186  
21              
22             our @ISA = qw(Excel::Writer::XLSX::Package::XMLwriter);
23             our $VERSION = '1.07';
24              
25              
26             ###############################################################################
27             #
28             # Public and private API methods.
29             #
30             ###############################################################################
31              
32              
33             ###############################################################################
34             #
35             # new()
36             #
37             # Constructor.
38             #
39             sub new {
40              
41 853     853 0 5194 my $class = shift;
42 853         1857 my $fh = shift;
43 853         3422 my $self = Excel::Writer::XLSX::Package::XMLwriter->new( $fh );
44              
45 853         2957 $self->{_part_names} = [];
46 853         2552 $self->{_heading_pairs} = [];
47 853         2369 $self->{_properties} = {};
48              
49 853         2139 bless $self, $class;
50              
51 853         2616 return $self;
52             }
53              
54              
55             ###############################################################################
56             #
57             # _assemble_xml_file()
58             #
59             # Assemble and write the XML file.
60             #
61             sub _assemble_xml_file {
62              
63 852     852   2376 my $self = shift;
64              
65 852         8158 $self->xml_declaration;
66 852         5008 $self->_write_properties();
67 852         3631 $self->_write_application();
68 852         3672 $self->_write_doc_security();
69 852         3615 $self->_write_scale_crop();
70 852         3579 $self->_write_heading_pairs();
71 852         3702 $self->_write_titles_of_parts();
72 852         3704 $self->_write_manager();
73 852         3615 $self->_write_company();
74 852         3939 $self->_write_links_up_to_date();
75 852         3471 $self->_write_shared_doc();
76 852         3519 $self->_write_hyperlink_base();
77 852         3578 $self->_write_hyperlinks_changed();
78 852         3362 $self->_write_app_version();
79              
80 852         3424 $self->xml_end_tag( 'Properties' );
81              
82             # Close the XML writer filehandle.
83 852         6653 $self->xml_get_fh()->close();
84             }
85              
86              
87             ###############################################################################
88             #
89             # _add_part_name()
90             #
91             # Add the name of a workbook Part such as 'Sheet1' or 'Print_Titles'.
92             #
93             sub _add_part_name {
94              
95 1039     1039   2348 my $self = shift;
96 1039         2643 my $part_name = shift;
97              
98 1039         2158 push @{ $self->{_part_names} }, $part_name;
  1039         4879  
99             }
100              
101              
102             ###############################################################################
103             #
104             # _add_heading_pair()
105             #
106             # Add the name of a workbook Heading Pair such as 'Worksheets', 'Charts' or
107             # 'Named Ranges'.
108             #
109             sub _add_heading_pair {
110              
111 1720     1720   3471 my $self = shift;
112 1720         2864 my $heading_pair = shift;
113              
114 1720 100       6227 return unless $heading_pair->[1]; # Ignore empty pairs such as chartsheets.
115              
116 889         4948 my @vector = (
117             [ 'lpstr', $heading_pair->[0] ], # Data name
118             [ 'i4', $heading_pair->[1] ], # Data size
119             );
120              
121 889         2333 push @{ $self->{_heading_pairs} }, @vector;
  889         7902  
122             }
123              
124              
125             ###############################################################################
126             #
127             # _set_properties()
128             #
129             # Set the document properties.
130             #
131             sub _set_properties {
132              
133 849     849   2306 my $self = shift;
134 849         2056 my $properties = shift;
135              
136 849         3339 $self->{_properties} = $properties;
137             }
138              
139              
140             ###############################################################################
141             #
142             # Internal methods.
143             #
144             ###############################################################################
145              
146              
147             ###############################################################################
148             #
149             # XML writing methods.
150             #
151             ###############################################################################
152              
153              
154             ###############################################################################
155             #
156             # _write_properties()
157             #
158             # Write the element.
159             #
160             sub _write_properties {
161              
162 852     852   2712 my $self = shift;
163 852         2661 my $schema = 'http://schemas.openxmlformats.org/officeDocument/2006/';
164 852         3768 my $xmlns = $schema . 'extended-properties';
165 852         2837 my $xmlns_vt = $schema . 'docPropsVTypes';
166              
167 852         3820 my @attributes = (
168             'xmlns' => $xmlns,
169             'xmlns:vt' => $xmlns_vt,
170             );
171              
172 852         5680 $self->xml_start_tag( 'Properties', @attributes );
173             }
174              
175             ###############################################################################
176             #
177             # _write_application()
178             #
179             # Write the element.
180             #
181             sub _write_application {
182              
183 852     852   2170 my $self = shift;
184 852         2251 my $data = 'Microsoft Excel';
185              
186 852         8092 $self->xml_data_element( 'Application', $data );
187             }
188              
189              
190             ###############################################################################
191             #
192             # _write_doc_security()
193             #
194             # Write the element.
195             #
196             sub _write_doc_security {
197              
198 852     852   2722 my $self = shift;
199 852         2014 my $data = 0;
200              
201 852         3448 $self->xml_data_element( 'DocSecurity', $data );
202             }
203              
204              
205             ###############################################################################
206             #
207             # _write_scale_crop()
208             #
209             # Write the element.
210             #
211             sub _write_scale_crop {
212              
213 852     852   3307 my $self = shift;
214 852         2285 my $data = 'false';
215              
216 852         3649 $self->xml_data_element( 'ScaleCrop', $data );
217             }
218              
219              
220             ###############################################################################
221             #
222             # _write_heading_pairs()
223             #
224             # Write the element.
225             #
226             sub _write_heading_pairs {
227              
228 852     852   3516 my $self = shift;
229              
230 852         3956 $self->xml_start_tag( 'HeadingPairs' );
231              
232 852         4192 $self->_write_vt_vector( 'variant', $self->{_heading_pairs} );
233              
234 852         3019 $self->xml_end_tag( 'HeadingPairs' );
235             }
236              
237              
238             ###############################################################################
239             #
240             # _write_titles_of_parts()
241             #
242             # Write the element.
243             #
244             sub _write_titles_of_parts {
245              
246 852     852   2163 my $self = shift;
247              
248 852         3681 $self->xml_start_tag( 'TitlesOfParts' );
249              
250 852         1840 my @parts_data;
251              
252 852         2044 for my $part_name ( @{ $self->{_part_names} } ) {
  852         3125  
253 1039         4269 push @parts_data, [ 'lpstr', $part_name ];
254             }
255              
256 852         3724 $self->_write_vt_vector( 'lpstr', \@parts_data );
257              
258 852         3288 $self->xml_end_tag( 'TitlesOfParts' );
259             }
260              
261              
262             ###############################################################################
263             #
264             # _write_vt_vector()
265             #
266             # Write the element.
267             #
268             sub _write_vt_vector {
269              
270 1704     1704   3536 my $self = shift;
271 1704         3567 my $base_type = shift;
272 1704         3087 my $data = shift;
273 1704         3910 my $size = @$data;
274              
275 1704         5766 my @attributes = (
276             'size' => $size,
277             'baseType' => $base_type,
278             );
279              
280 1704         6168 $self->xml_start_tag( 'vt:vector', @attributes );
281              
282 1704         5093 for my $aref ( @$data ) {
283 2817 100       10942 $self->xml_start_tag( 'vt:variant' ) if $base_type eq 'variant';
284 2817         8500 $self->_write_vt_data( @$aref );
285 2817 100       11929 $self->xml_end_tag( 'vt:variant' ) if $base_type eq 'variant';
286             }
287              
288 1704         4823 $self->xml_end_tag( 'vt:vector' );
289             }
290              
291              
292             ##############################################################################
293             #
294             # _write_vt_data()
295             #
296             # Write the elements such as and .
297             #
298             sub _write_vt_data {
299              
300 2817     2817   4873 my $self = shift;
301 2817         5177 my $type = shift;
302 2817         4765 my $data = shift;
303              
304 2817         9533 $self->xml_data_element( "vt:$type", $data );
305             }
306              
307              
308             ###############################################################################
309             #
310             # _write_company()
311             #
312             # Write the element.
313             #
314             sub _write_company {
315              
316 852     852   2050 my $self = shift;
317 852   100     6764 my $data = $self->{_properties}->{company} || '';
318              
319 852         3997 $self->xml_data_element( 'Company', $data );
320             }
321              
322              
323             ###############################################################################
324             #
325             # _write_manager()
326             #
327             # Write the element.
328             #
329             sub _write_manager {
330              
331 852     852   2259 my $self = shift;
332 852         2513 my $data = $self->{_properties}->{manager};
333              
334 852 100       3636 return unless $data;
335              
336 1         5 $self->xml_data_element( 'Manager', $data );
337             }
338              
339              
340             ###############################################################################
341             #
342             # _write_links_up_to_date()
343             #
344             # Write the element.
345             #
346             sub _write_links_up_to_date {
347              
348 852     852   2209 my $self = shift;
349 852         2139 my $data = 'false';
350              
351 852         3069 $self->xml_data_element( 'LinksUpToDate', $data );
352             }
353              
354              
355             ###############################################################################
356             #
357             # _write_shared_doc()
358             #
359             # Write the element.
360             #
361             sub _write_shared_doc {
362              
363 852     852   2086 my $self = shift;
364 852         2085 my $data = 'false';
365              
366 852         3095 $self->xml_data_element( 'SharedDoc', $data );
367             }
368              
369              
370             ###############################################################################
371             #
372             # _write_hyperlink_base()
373             #
374             # Write the element.
375             #
376             sub _write_hyperlink_base {
377              
378 852     852   2204 my $self = shift;
379 852         2213 my $data = $self->{_properties}->{hyperlink_base};
380              
381 852 100       3484 return unless $data;
382              
383 1         4 $self->xml_data_element( 'HyperlinkBase', $data );
384             }
385              
386              
387             ###############################################################################
388             #
389             # _write_hyperlinks_changed()
390             #
391             # Write the element.
392             #
393             sub _write_hyperlinks_changed {
394              
395 852     852   2152 my $self = shift;
396 852         2083 my $data = 'false';
397              
398 852         3346 $self->xml_data_element( 'HyperlinksChanged', $data );
399             }
400              
401              
402             ###############################################################################
403             #
404             # _write_app_version()
405             #
406             # Write the element.
407             #
408             sub _write_app_version {
409              
410 852     852   2166 my $self = shift;
411 852         2051 my $data = '12.0000';
412              
413 852         3184 $self->xml_data_element( 'AppVersion', $data );
414             }
415              
416              
417             1;
418              
419              
420             __END__