Template/Engine/TT2/Provider.pm

filter: Statementstmt 100% 20 / 20 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 90.0% 27 / 30 CC 4 SCAR 10.3
CC
4
Cov
88%
_template_content
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
« Template/Engine.pm ↑ Summary Template/Engine/Mustache.pm »
1 package MsOffice::Word::Template::Engine::TT2::Provider;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base 'Template::Provider';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '2.05';
7  
8  
9 1 ▶sub _template_content {
Subroutine _template_content: called CC=4 SCAR=14.2
10 1 my ($self, $path) = @_;
11  
12 1 ▶ $path
Branch: 1 branch
BranchTrueFalseTotal
$path or return undef, "No path specified to fetch content from " 1 0 1
13 or return (undef, "No path specified to fetch content from ");
14  
15 # if the path is not a Microsoft Word document, let the parent class handle it
16 1 ▶ $path =~ /\.do[ct][xm]?$/
Branch: 1 branch
BranchTrueFalseTotal
$path =~ /\.do[ct][xm]?$/ or return $self->SUPER::_template_content($path) 1 0 1
17 or return $self->SUPER::_template_content($path);
18  
19 # parse the subtemplate
20 1 my $mod_date = (stat($path))[9];
21 1 my $subtemplate = MsOffice::Word::Template->new($path);
22 1 my $doc_part = $subtemplate->surgeon->part("document");
23 1 my $data = $subtemplate->engine->template_text_for_part($doc_part);
24  
25 # just keep the XML inside the document body
26 1 $data =~ s{^.*?<w:body>(.*?)</w:body>.*}{$1}s;
27  
28 # comply with the Provider API (see below)
29 1 ▶ return wantarray ? ( $data, undef, $mod_date )
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
30 : $data;
31 }
32  
33 #------------------------------------------------------------------------
34 # _template_content($path)
35 #
36 # Fetches content pointed to by $path.
37 # Returns the content in scalar context.
38 # Returns ($data, $error, $mtime) in list context where
39 # $data - content
40 # $error - error string if there was an error, otherwise undef
41 # $mtime - last modified time from calling stat() on the path
42 #------------------------------------------------------------------------
43  
44  
45  
46 1 1;
47  
48 __END__
« Template/Engine.pm ↑ Summary Template/Engine/Mustache.pm »