| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Excel::Writer::XLSX::Package::Custom; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | ############################################################################### | 
| 4 |  |  |  |  |  |  | # | 
| 5 |  |  |  |  |  |  | # Custom - A class for writing the Excel XLSX custom.xml file for custom | 
| 6 |  |  |  |  |  |  | # workbook properties. | 
| 7 |  |  |  |  |  |  | # | 
| 8 |  |  |  |  |  |  | # Used in conjunction with Excel::Writer::XLSX | 
| 9 |  |  |  |  |  |  | # | 
| 10 |  |  |  |  |  |  | # Copyright 2000-2019, John McNamara, jmcnamara@cpan.org | 
| 11 |  |  |  |  |  |  | # | 
| 12 |  |  |  |  |  |  | # Documentation after __END__ | 
| 13 |  |  |  |  |  |  | # | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | # perltidy with the following options: -mbl=2 -pt=0 -nola | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 1040 |  |  | 1040 |  | 18048 | use 5.008002; | 
|  | 1040 |  |  |  |  | 3837 |  | 
| 18 | 1040 |  |  | 1040 |  | 8170 | use strict; | 
|  | 1040 |  |  |  |  | 3424 |  | 
|  | 1040 |  |  |  |  | 23221 |  | 
| 19 | 1040 |  |  | 1040 |  | 6416 | use warnings; | 
|  | 1040 |  |  |  |  | 3629 |  | 
|  | 1040 |  |  |  |  | 27423 |  | 
| 20 | 1040 |  |  | 1040 |  | 6572 | use Carp; | 
|  | 1040 |  |  |  |  | 2270 |  | 
|  | 1040 |  |  |  |  | 60748 |  | 
| 21 | 1040 |  |  | 1040 |  | 8358 | use Excel::Writer::XLSX::Package::XMLwriter; | 
|  | 1040 |  |  |  |  | 2910 |  | 
|  | 1040 |  |  |  |  | 657632 |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | our @ISA     = qw(Excel::Writer::XLSX::Package::XMLwriter); | 
| 24 |  |  |  |  |  |  | our $VERSION = '1.03'; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | ############################################################################### | 
| 28 |  |  |  |  |  |  | # | 
| 29 |  |  |  |  |  |  | # Public and private API methods. | 
| 30 |  |  |  |  |  |  | # | 
| 31 |  |  |  |  |  |  | ############################################################################### | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | ############################################################################### | 
| 35 |  |  |  |  |  |  | # | 
| 36 |  |  |  |  |  |  | # new() | 
| 37 |  |  |  |  |  |  | # | 
| 38 |  |  |  |  |  |  | # Constructor. | 
| 39 |  |  |  |  |  |  | # | 
| 40 |  |  |  |  |  |  | sub new { | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 809 |  |  | 809 | 0 | 2784 | my $class = shift; | 
| 43 | 809 |  |  |  |  | 1908 | my $fh    = shift; | 
| 44 | 809 |  |  |  |  | 3783 | my $self  = Excel::Writer::XLSX::Package::XMLwriter->new( $fh ); | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 809 |  |  |  |  | 3336 | $self->{_properties} = []; | 
| 47 | 809 |  |  |  |  | 2758 | $self->{_pid}        = 1; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 809 |  |  |  |  | 2291 | bless $self, $class; | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 809 |  |  |  |  | 2694 | 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 | 4 |  |  | 4 |  | 9 | my $self = shift; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 4 |  |  |  |  | 30 | $self->xml_declaration; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 4 |  |  |  |  | 18 | $self->_write_properties(); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 4 |  |  |  |  | 16 | $self->xml_end_tag( 'Properties' ); | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | # Close the XML writer filehandle. | 
| 72 | 4 |  |  |  |  | 16 | $self->xml_get_fh()->close(); | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | ############################################################################### | 
| 77 |  |  |  |  |  |  | # | 
| 78 |  |  |  |  |  |  | # _set_properties() | 
| 79 |  |  |  |  |  |  | # | 
| 80 |  |  |  |  |  |  | # Set the document properties. | 
| 81 |  |  |  |  |  |  | # | 
| 82 |  |  |  |  |  |  | sub _set_properties { | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 4 |  |  | 4 |  | 9 | my $self       = shift; | 
| 85 | 4 |  |  |  |  | 8 | my $properties = shift; | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 4 |  |  |  |  | 23 | $self->{_properties} = $properties; | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | ############################################################################### | 
| 92 |  |  |  |  |  |  | # | 
| 93 |  |  |  |  |  |  | # Internal methods. | 
| 94 |  |  |  |  |  |  | # | 
| 95 |  |  |  |  |  |  | ############################################################################### | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | ############################################################################### | 
| 99 |  |  |  |  |  |  | # | 
| 100 |  |  |  |  |  |  | # XML writing methods. | 
| 101 |  |  |  |  |  |  | # | 
| 102 |  |  |  |  |  |  | ############################################################################### | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | ############################################################################### | 
| 106 |  |  |  |  |  |  | # | 
| 107 |  |  |  |  |  |  | # _write_properties() | 
| 108 |  |  |  |  |  |  | # | 
| 109 |  |  |  |  |  |  | # Write the  element. | 
| 110 |  |  |  |  |  |  | # | 
| 111 |  |  |  |  |  |  | sub _write_properties { | 
| 112 |  |  |  |  |  |  |  | 
| 113 | 4 |  |  | 4 |  | 12 | my $self     = shift; | 
| 114 | 4 |  |  |  |  | 9 | my $schema   = 'http://schemas.openxmlformats.org/officeDocument/2006/'; | 
| 115 | 4 |  |  |  |  | 13 | my $xmlns    = $schema . 'custom-properties'; | 
| 116 | 4 |  |  |  |  | 11 | my $xmlns_vt = $schema . 'docPropsVTypes'; | 
| 117 |  |  |  |  |  |  |  | 
| 118 | 4 |  |  |  |  | 15 | my @attributes = ( | 
| 119 |  |  |  |  |  |  | 'xmlns'    => $xmlns, | 
| 120 |  |  |  |  |  |  | 'xmlns:vt' => $xmlns_vt, | 
| 121 |  |  |  |  |  |  | ); | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 4 |  |  |  |  | 21 | $self->xml_start_tag( 'Properties', @attributes ); | 
| 124 |  |  |  |  |  |  |  | 
| 125 | 4 |  |  |  |  | 8 | for my $property ( @{ $self->{_properties} } ) { | 
|  | 4 |  |  |  |  | 20 |  | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | # Write the property element. | 
| 128 | 18 |  |  |  |  | 43 | $self->_write_property( $property ); | 
| 129 |  |  |  |  |  |  | } | 
| 130 |  |  |  |  |  |  | } | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | ############################################################################## | 
| 133 |  |  |  |  |  |  | # | 
| 134 |  |  |  |  |  |  | # _write_property() | 
| 135 |  |  |  |  |  |  | # | 
| 136 |  |  |  |  |  |  | # Write the  element. | 
| 137 |  |  |  |  |  |  | # | 
| 138 |  |  |  |  |  |  | sub _write_property { | 
| 139 |  |  |  |  |  |  |  | 
| 140 | 18 |  |  | 18 |  | 30 | my $self     = shift; | 
| 141 | 18 |  |  |  |  | 28 | my $property = shift; | 
| 142 | 18 |  |  |  |  | 22 | my $fmtid    = '{D5CDD505-2E9C-101B-9397-08002B2CF9AE}'; | 
| 143 |  |  |  |  |  |  |  | 
| 144 | 18 |  |  |  |  | 66 | $self->{_pid}++; | 
| 145 |  |  |  |  |  |  |  | 
| 146 | 18 |  |  |  |  | 44 | my ( $name, $value, $type ) = @$property; | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | my @attributes = ( | 
| 150 |  |  |  |  |  |  | 'fmtid' => $fmtid, | 
| 151 |  |  |  |  |  |  | 'pid'   => $self->{_pid}, | 
| 152 | 18 |  |  |  |  | 47 | 'name'  => $name, | 
| 153 |  |  |  |  |  |  | ); | 
| 154 |  |  |  |  |  |  |  | 
| 155 | 18 |  |  |  |  | 48 | $self->xml_start_tag( 'property', @attributes ); | 
| 156 |  |  |  |  |  |  |  | 
| 157 | 18 | 100 |  |  |  | 86 | if ( $type eq 'date' ) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | # Write the vt:filetime element. | 
| 160 | 2 |  |  |  |  | 6 | $self->_write_vt_filetime( $value ); | 
| 161 |  |  |  |  |  |  | } | 
| 162 |  |  |  |  |  |  | elsif ( $type eq 'number' ) { | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | # Write the vt:r8 element. | 
| 165 | 4 |  |  |  |  | 13 | $self->_write_vt_r8( $value ); | 
| 166 |  |  |  |  |  |  | } | 
| 167 |  |  |  |  |  |  | elsif ( $type eq 'number_int' ) { | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | # Write the vt:i4 element. | 
| 170 | 2 |  |  |  |  | 6 | $self->_write_vt_i4( $value ); | 
| 171 |  |  |  |  |  |  | } | 
| 172 |  |  |  |  |  |  | elsif ( $type eq 'bool' ) { | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | # Write the vt:bool element. | 
| 175 | 4 |  |  |  |  | 11 | $self->_write_vt_bool( $value ); | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  | else { | 
| 178 |  |  |  |  |  |  |  | 
| 179 |  |  |  |  |  |  | # Write the vt:lpwstr element. | 
| 180 | 6 |  |  |  |  | 16 | $self->_write_vt_lpwstr( $value ); | 
| 181 |  |  |  |  |  |  | } | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  |  | 
| 184 | 18 |  |  |  |  | 49 | $self->xml_end_tag( 'property' ); | 
| 185 |  |  |  |  |  |  | } | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | ############################################################################## | 
| 189 |  |  |  |  |  |  | # | 
| 190 |  |  |  |  |  |  | # _write_vt_lpwstr() | 
| 191 |  |  |  |  |  |  | # | 
| 192 |  |  |  |  |  |  | # Write the  element. | 
| 193 |  |  |  |  |  |  | # | 
| 194 |  |  |  |  |  |  | sub _write_vt_lpwstr { | 
| 195 |  |  |  |  |  |  |  | 
| 196 | 6 |  |  | 6 |  | 14 | my $self = shift; | 
| 197 | 6 |  |  |  |  | 10 | my $data = shift; | 
| 198 |  |  |  |  |  |  |  | 
| 199 | 6 |  |  |  |  | 23 | $self->xml_data_element( 'vt:lpwstr', $data ); | 
| 200 |  |  |  |  |  |  | } | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | ############################################################################## | 
| 204 |  |  |  |  |  |  | # | 
| 205 |  |  |  |  |  |  | # _write_vt_i4() | 
| 206 |  |  |  |  |  |  | # | 
| 207 |  |  |  |  |  |  | # Write the  element. | 
| 208 |  |  |  |  |  |  | # | 
| 209 |  |  |  |  |  |  | sub _write_vt_i4 { | 
| 210 |  |  |  |  |  |  |  | 
| 211 | 2 |  |  | 2 |  | 4 | my $self = shift; | 
| 212 | 2 |  |  |  |  | 4 | my $data = shift; | 
| 213 |  |  |  |  |  |  |  | 
| 214 | 2 |  |  |  |  | 8 | $self->xml_data_element( 'vt:i4', $data ); | 
| 215 |  |  |  |  |  |  | } | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | ############################################################################## | 
| 219 |  |  |  |  |  |  | # | 
| 220 |  |  |  |  |  |  | # _write_vt_r8() | 
| 221 |  |  |  |  |  |  | # | 
| 222 |  |  |  |  |  |  | # Write the  element. | 
| 223 |  |  |  |  |  |  | # | 
| 224 |  |  |  |  |  |  | sub _write_vt_r8 { | 
| 225 |  |  |  |  |  |  |  | 
| 226 | 4 |  |  | 4 |  | 8 | my $self = shift; | 
| 227 | 4 |  |  |  |  | 7 | my $data = shift; | 
| 228 |  |  |  |  |  |  |  | 
| 229 | 4 |  |  |  |  | 8 | $self->xml_data_element( 'vt:r8', $data ); | 
| 230 |  |  |  |  |  |  | } | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  |  | 
| 233 |  |  |  |  |  |  | ############################################################################## | 
| 234 |  |  |  |  |  |  | # | 
| 235 |  |  |  |  |  |  | # _write_vt_bool() | 
| 236 |  |  |  |  |  |  | # | 
| 237 |  |  |  |  |  |  | # Write the  element. | 
| 238 |  |  |  |  |  |  | # | 
| 239 |  |  |  |  |  |  | sub _write_vt_bool { | 
| 240 |  |  |  |  |  |  |  | 
| 241 | 4 |  |  | 4 |  | 8 | my $self = shift; | 
| 242 | 4 |  |  |  |  | 5 | my $data = shift; | 
| 243 |  |  |  |  |  |  |  | 
| 244 | 4 | 100 |  |  |  | 10 | if ( $data ) { | 
| 245 | 2 |  |  |  |  | 4 | $data = 'true'; | 
| 246 |  |  |  |  |  |  | } | 
| 247 |  |  |  |  |  |  | else { | 
| 248 | 2 |  |  |  |  | 5 | $data = 'false'; | 
| 249 |  |  |  |  |  |  | } | 
| 250 |  |  |  |  |  |  |  | 
| 251 | 4 |  |  |  |  | 11 | $self->xml_data_element( 'vt:bool', $data ); | 
| 252 |  |  |  |  |  |  | } | 
| 253 |  |  |  |  |  |  |  | 
| 254 |  |  |  |  |  |  | ############################################################################## | 
| 255 |  |  |  |  |  |  | # | 
| 256 |  |  |  |  |  |  | # _write_vt_filetime() | 
| 257 |  |  |  |  |  |  | # | 
| 258 |  |  |  |  |  |  | # Write the  element. | 
| 259 |  |  |  |  |  |  | # | 
| 260 |  |  |  |  |  |  | sub _write_vt_filetime { | 
| 261 |  |  |  |  |  |  |  | 
| 262 | 2 |  |  | 2 |  | 5 | my $self = shift; | 
| 263 | 2 |  |  |  |  | 5 | my $data = shift; | 
| 264 |  |  |  |  |  |  |  | 
| 265 | 2 |  |  |  |  | 5 | $self->xml_data_element( 'vt:filetime', $data ); | 
| 266 |  |  |  |  |  |  | } | 
| 267 |  |  |  |  |  |  |  | 
| 268 |  |  |  |  |  |  |  | 
| 269 |  |  |  |  |  |  | 1; | 
| 270 |  |  |  |  |  |  |  | 
| 271 |  |  |  |  |  |  |  | 
| 272 |  |  |  |  |  |  | __END__ |