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-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 1040     1040   17538 use 5.008002;
  1040         5098  
17 1040     1040   5629 use strict;
  1040         5840  
  1040         22460  
18 1040     1040   6582 use warnings;
  1040         3501  
  1040         26562  
19 1040     1040   6774 use Carp;
  1040         3673  
  1040         59199  
20 1040     1040   7527 use Excel::Writer::XLSX::Package::XMLwriter;
  1040         3815  
  1040         1163616  
21              
22             our @ISA = qw(Excel::Writer::XLSX::Package::XMLwriter);
23             our $VERSION = '1.03';
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 813     813 0 5698 my $class = shift;
42 813         1944 my $fh = shift;
43 813         3397 my $self = Excel::Writer::XLSX::Package::XMLwriter->new( $fh );
44              
45 813         3121 $self->{_part_names} = [];
46 813         2591 $self->{_heading_pairs} = [];
47 813         2432 $self->{_properties} = {};
48              
49 813         2232 bless $self, $class;
50              
51 813         2609 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 812     812   3103 my $self = shift;
64              
65 812         8710 $self->xml_declaration;
66 812         5125 $self->_write_properties();
67 812         4406 $self->_write_application();
68 812         4433 $self->_write_doc_security();
69 812         4541 $self->_write_scale_crop();
70 812         4112 $self->_write_heading_pairs();
71 812         4036 $self->_write_titles_of_parts();
72 812         4191 $self->_write_manager();
73 812         3639 $self->_write_company();
74 812         4457 $self->_write_links_up_to_date();
75 812         3922 $self->_write_shared_doc();
76 812         4176 $self->_write_hyperlink_base();
77 812         3587 $self->_write_hyperlinks_changed();
78 812         4051 $self->_write_app_version();
79              
80 812         4019 $self->xml_end_tag( 'Properties' );
81              
82             # Close the XML writer filehandle.
83 812         7459 $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 999     999   3152 my $self = shift;
96 999         2893 my $part_name = shift;
97              
98 999         2445 push @{ $self->{_part_names} }, $part_name;
  999         4555  
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 1640     1640   3637 my $self = shift;
112 1640         3193 my $heading_pair = shift;
113              
114 1640 100       6074 return unless $heading_pair->[1]; # Ignore empty pairs such as chartsheets.
115              
116 849         5621 my @vector = (
117             [ 'lpstr', $heading_pair->[0] ], # Data name
118             [ 'i4', $heading_pair->[1] ], # Data size
119             );
120              
121 849         2084 push @{ $self->{_heading_pairs} }, @vector;
  849         8111  
122             }
123              
124              
125             ###############################################################################
126             #
127             # _set_properties()
128             #
129             # Set the document properties.
130             #
131             sub _set_properties {
132              
133 809     809   2257 my $self = shift;
134 809         1968 my $properties = shift;
135              
136 809         3043 $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 812     812   2423 my $self = shift;
163 812         2575 my $schema = 'http://schemas.openxmlformats.org/officeDocument/2006/';
164 812         3510 my $xmlns = $schema . 'extended-properties';
165 812         2860 my $xmlns_vt = $schema . 'docPropsVTypes';
166              
167 812         3770 my @attributes = (
168             'xmlns' => $xmlns,
169             'xmlns:vt' => $xmlns_vt,
170             );
171              
172 812         5931 $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 812     812   2221 my $self = shift;
184 812         3019 my $data = 'Microsoft Excel';
185              
186 812         7609 $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 812     812   2554 my $self = shift;
199 812         2871 my $data = 0;
200              
201 812         3524 $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 812     812   2311 my $self = shift;
214 812         2188 my $data = 'false';
215              
216 812         3132 $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 812     812   2344 my $self = shift;
229              
230 812         4008 $self->xml_start_tag( 'HeadingPairs' );
231              
232 812         4847 $self->_write_vt_vector( 'variant', $self->{_heading_pairs} );
233              
234 812         3129 $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 812     812   2258 my $self = shift;
247              
248 812         3693 $self->xml_start_tag( 'TitlesOfParts' );
249              
250 812         1910 my @parts_data;
251              
252 812         2111 for my $part_name ( @{ $self->{_part_names} } ) {
  812         3177  
253 999         4292 push @parts_data, [ 'lpstr', $part_name ];
254             }
255              
256 812         4093 $self->_write_vt_vector( 'lpstr', \@parts_data );
257              
258 812         3417 $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 1624     1624   3964 my $self = shift;
271 1624         3737 my $base_type = shift;
272 1624         3153 my $data = shift;
273 1624         4563 my $size = @$data;
274              
275 1624         5817 my @attributes = (
276             'size' => $size,
277             'baseType' => $base_type,
278             );
279              
280 1624         6820 $self->xml_start_tag( 'vt:vector', @attributes );
281              
282 1624         5290 for my $aref ( @$data ) {
283 2697 100       11961 $self->xml_start_tag( 'vt:variant' ) if $base_type eq 'variant';
284 2697         8951 $self->_write_vt_data( @$aref );
285 2697 100       12968 $self->xml_end_tag( 'vt:variant' ) if $base_type eq 'variant';
286             }
287              
288 1624         5501 $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 2697     2697   5414 my $self = shift;
301 2697         4921 my $type = shift;
302 2697         4895 my $data = shift;
303              
304 2697         9444 $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 812     812   2504 my $self = shift;
317 812   100     6845 my $data = $self->{_properties}->{company} || '';
318              
319 812         3841 $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 812     812   2586 my $self = shift;
332 812         2365 my $data = $self->{_properties}->{manager};
333              
334 812 100       3870 return unless $data;
335              
336 1         4 $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 812     812   2320 my $self = shift;
349 812         2376 my $data = 'false';
350              
351 812         3118 $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 812     812   2286 my $self = shift;
364 812         2273 my $data = 'false';
365              
366 812         3215 $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 812     812   2380 my $self = shift;
379 812         2599 my $data = $self->{_properties}->{hyperlink_base};
380              
381 812 100       3374 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 812     812   2566 my $self = shift;
396 812         2321 my $data = 'false';
397              
398 812         3192 $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 812     812   2155 my $self = shift;
411 812         2252 my $data = '12.0000';
412              
413 812         3116 $self->xml_data_element( 'AppVersion', $data );
414             }
415              
416              
417             1;
418              
419              
420             __END__