Wright/OpenDocument.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 65 CC 2 SCAR 9.8
CC
2
Cov
0%
close
6.0
BEGIN
2.0
_make_meta
2.0
CRAP 2.7
1 package Spreadsheet::Wright::OpenDocument;
2  
3 use 5.010;
4 use strict;
5 use warnings;
6 no warnings qw( uninitialized numeric );
7  
8 BEGIN {
9 $Spreadsheet::Wright::OpenDocument::VERSION = '0.107';
10 $Spreadsheet::Wright::OpenDocument::AUTHORITY = 'cpan:TOBYINK';
11 }
12  
13 use Archive::Zip qw':CONSTANTS';
14 use Carp;
15 use DateTime;
16  
17 use parent qw(Spreadsheet::Wright::OpenDocumentXML);
18  
19 our $MANIFEST_XML = <<MANIFEST;
20 <?xml version="1.0" encoding="UTF-8"?>
21 <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
22 <manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.spreadsheet" manifest:full-path="/"/>
23 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>
24 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>
25 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="settings.xml"/>
26 <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>
27 </manifest:manifest>
28 MANIFEST
29  
30 our $SETTINGS_XML = <<SETTINGS;
31 <?xml version="1.0" ?>
32 <office:document-settings office:version="1.0"
33 xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" />
34 SETTINGS
35  
36 our $STYLES_XML = <<STYLES;
37 <office:document-styles office:version="1.0"
38 xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
39 xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
40 xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0">
41 <!-- These don't work. Hopefully in a future version. -->
42 <office:styles>
43 <style:style style:family="paragraph" style:name="Bold" style:display-name="Bold" style:class="text">
44 <style:text-properties fo:font-weight="bold" />
45 </style:style>
46 <style:style style:family="paragraph" style:name="Italic" style:display-name="Italic" style:class="text">
47 <style:text-properties fo:font-style="italic" />
48 </style:style>
49 <style:style style:family="paragraph" style:name="BoldItalic" style:display-name="Bold Italic" style:class="text">
50 <style:text-properties fo:font-weight="bold" fo:font-style="italic" />
51 </style:style>
52 </office:styles>
53 </office:document-styles>
54 STYLES
55  
56 sub close
57 {
58 my $self=shift;
59 return if $self->{'_CLOSED'};
60  
61 my $CONTENT_XML = $self->_make_output;
62 my $META_XML = $self->_make_meta;
63 my $zip = Archive::Zip->new;
64 $zip->addString($MANIFEST_XML, 'META-INF/manifest.xml');
65 $zip->addString($STYLES_XML, 'styles.xml');
66 $zip->addString($META_XML, 'meta.xml');
67 $zip->addString($SETTINGS_XML, 'settings.xml');
68 $zip->addString($CONTENT_XML, 'content.xml')->desiredCompressionLevel(9);
69 $zip->addString('application/vnd.oasis.opendocument.spreadsheet', 'mimetype');
70 $zip->writeToFileHandle( $self->{'_FH'} );
71 $self->{'_FH'}->close;
72
73 $self->{'_CLOSED'}=1;
74 return $self;
75 }
76  
77 sub _make_meta
78 {
79 my $self = shift;
80
81 my $title = $self->{'options'}->{'title'};
82 $title =~ s/[^A-Za-z0-9 -]/sprintf('&#%d;', ord($1))/eg;
83
84 my $date = DateTime->now;
85
86 return sprintf(<<'META', $title, $date, $date, __PACKAGE__, $self->VERSION);
87 <?xml version="1.0" ?>
88 <office:document-meta office:version="1.0"
89 xmlns:dc="http://purl.org/dc/elements/1.1/"
90 xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
91 xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">
92 <office:meta>
93 <dc:title>%s</dc:title>
94 <dc:date>%s</dc:date>
95 <meta:creation-date>%s</meta:creation-date>
96 <meta:generator>%s/%s</meta:generator>
97 </office:meta>
98 </office:document-meta>
99 META
100 }
101  
102 1;