blib/lib/Template/Provider/OpenOffice.pm

filter: Statementstmt 32.5% 14 / 43 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 50.0% 4 / 8 Podpod 50.0% 1 / 2 totaltotal 21.1% 19 / 90 CC 15 SCAR 49.0
CC
15
Cov
19%
_load
210.0
new
6.0
get_oo
2.0
CRAP 134.5
↑ Summary
1 package Template::Provider::OpenOffice;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use OpenOffice::OODoc::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use base qw/Template::Provider/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.01';
10  
11 # Basic extension of base class with undefined OO_DOC
12 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
13 0 my $class = shift;
14 0 ▶ my $options = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
15 0 my $self = $class->SUPER::new( $options );
16  
17 0 $self->{OO_DOC} = "";
18  
19 0 return $self;
20 }
21  
22 # Used to get the OO_DOC object once created (for use by _output) in main Template
23 0 ▶sub get_oo {
Subroutine get_oo: not called CC=1 SCAR=6.9
Pod undocumented
24 0 my $self = shift;
25 0 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 0 ▶sub _load {
Subroutine _load: not called CC=14 SCAR=53.5
32 0 my ($self, $name, $alias) = @_;
33 0 my ($data, $error);
34 0 my $now = time;
35  
36 0 ▶ $alias = $name unless defined $alias or ref $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $alias or ref $name 0 0 0
Condition0%0/3
defined $alias or ref $name
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $alias or ref $name
defined $alias ref $name
Truth table0%0/3
A or B
A= defined $aliasB= ref $name
ABresult
1X1
011
000
37  
38 $self->debug("_load($name, ", defined $alias ? $alias : '<no alias>',
39 0 ▶ ')') if $self->{ DEBUG };
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
defined $alias ? : 0 0 0
40  
41 0 ▶ if (ref $name) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $name) { } 0 0 0
elsif (-f $name) { } 0 0 0
42 0 ▶ return (undef, Template::Constants::STATUS_DECLINED) if ($self->{ TOLERANT });
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"TOLERANT"} 0 0 0
43 0 return ("$alias: GLOB/References not supported",Template::Constants::STATUS_ERROR);
44 }
45 elsif (-f $name) {
46 0 my $text;
47  
48 0 eval {
49 0 ▶ local $SIG{'__WARN__'} = sub { die $_[0]} ;
Subroutine __ANON__: not called CC=1 SCAR=6.9
50  
51 # Don't attempt to read if we don't have a valid archive
52 0 ▶ if ($self->{OO_DOC} = OpenOffice::OODoc::File->new($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OO_DOC"} = "OpenOffice::OODoc::File"->new($name)) 0 0 0
53 0 $text = $self->{OO_DOC}->extract('content.xml');
54 }
55 };
56  
57 0 $error = $@;
58  
59 0 ▶ unless ($text) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text) 0 0 0
60 0 ▶ return (undef, Template::Constants::STATUS_DECLINED) if ($self->{ TOLERANT });
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"TOLERANT"} 0 0 0
61 0 return ("$alias: $error", Template::Constants::STATUS_ERROR);
62 }
63  
64 $data = {
65 0 name => $alias,
66 path => $name,
67 text => $text,
68 time => (stat $name)[9],
69 load => $now,
70 };
71 }
72 else {
73 0 ($data, $error) = (undef, Template::Constants::STATUS_DECLINED);
74 }
75
76 $data->{ path } = $data->{ name }
77 0 ▶ if $data and ref $data and ! defined $data->{ path };
Branch: 1 branch
BranchTrueFalseTotal
if $data and ref $data and not defined $data->{"path"} 0 0 0
Condition0%0/6
$data and ref $data and not defined $data->{"path"}
!ll&&!rl&&r
000
$data and ref $data
!ll&&!rl&&r
000
MC/DC0%0/3
$data and ref $data and not defined $data->{"path"}
$data ref $data not defined $data->{"path"}
Truth table0%0/4
A and B and not(C)
A= $dataB= ref $dataC= not defined $data->{"path"}
ABCresult
0XX0
10X0
1100
1111
78  
79 0 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 E<lt>abrezinsky@brevient.comE<gt>
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 1;
↑ Summary