line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Template::Provider::OpenOffice; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
26260
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
386
|
use OpenOffice::OODoc::File; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use base qw/Template::Provider/; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Basic extension of base class with undefined OO_DOC |
12
|
|
|
|
|
|
|
sub new { |
13
|
|
|
|
|
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
my $options = shift || {}; |
15
|
|
|
|
|
|
|
my $self = $class->SUPER::new( $options ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$self->{OO_DOC} = ""; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Used to get the OO_DOC object once created (for use by _output) in main Template |
23
|
|
|
|
|
|
|
sub get_oo { |
24
|
|
|
|
|
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
return $self->{OO_DOC}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Overload our _load function to extract our xml from the openoffice file |
29
|
|
|
|
|
|
|
# borrowed a bit from the Template::Provider |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _load { |
32
|
|
|
|
|
|
|
my ($self, $name, $alias) = @_; |
33
|
|
|
|
|
|
|
my ($data, $error); |
34
|
|
|
|
|
|
|
my $now = time; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$alias = $name unless defined $alias or ref $name; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$self->debug("_load($name, ", defined $alias ? $alias : '', |
39
|
|
|
|
|
|
|
')') if $self->{ DEBUG }; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
if (ref $name) { |
42
|
|
|
|
|
|
|
return (undef, Template::Constants::STATUS_DECLINED) if ($self->{ TOLERANT }); |
43
|
|
|
|
|
|
|
return ("$alias: GLOB/References not supported",Template::Constants::STATUS_ERROR); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif (-f $name) { |
46
|
|
|
|
|
|
|
my $text; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
eval { |
49
|
|
|
|
|
|
|
local $SIG{'__WARN__'} = sub { die $_[0]} ; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Don't attempt to read if we don't have a valid archive |
52
|
|
|
|
|
|
|
if ($self->{OO_DOC} = OpenOffice::OODoc::File->new($name)) { |
53
|
|
|
|
|
|
|
$text = $self->{OO_DOC}->extract('content.xml'); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$error = $@; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
unless ($text) { |
60
|
|
|
|
|
|
|
return (undef, Template::Constants::STATUS_DECLINED) if ($self->{ TOLERANT }); |
61
|
|
|
|
|
|
|
return ("$alias: $error", Template::Constants::STATUS_ERROR); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$data = { |
65
|
|
|
|
|
|
|
name => $alias, |
66
|
|
|
|
|
|
|
path => $name, |
67
|
|
|
|
|
|
|
text => $text, |
68
|
|
|
|
|
|
|
time => (stat $name)[9], |
69
|
|
|
|
|
|
|
load => $now, |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
|
|
|
|
|
|
($data, $error) = (undef, Template::Constants::STATUS_DECLINED); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$data->{ path } = $data->{ name } |
77
|
|
|
|
|
|
|
if $data and ref $data and ! defined $data->{ path }; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
return ($data, $error); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Template::Provider::OpenOffice - OpenOffice (ODT) Provider for Template Toolkit |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 DESCRIPTION |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This module extends Template::Provider to automatically extract the |
91
|
|
|
|
|
|
|
content.xml file from an OpenOffice zip file and run it through |
92
|
|
|
|
|
|
|
Template::Toolkit for processing. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
We use OpenOffice::OODoc to actually open the document and extract |
95
|
|
|
|
|
|
|
the content.xml file. This gives us the benefit of having the |
96
|
|
|
|
|
|
|
methods available to add/subtract files in addition to parsing |
97
|
|
|
|
|
|
|
and processing the content file if we want to do some custom work |
98
|
|
|
|
|
|
|
in addition to templating. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Andy Brezinsky Eabrezinsky@brevient.comE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 VERSION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Template::Provider::OpenOffice version 0.01, released 20 Sept 2006 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 COPYRIGHT |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Copyright (C) 2006 Brevient Technologies, Inc. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
113
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |