line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# WebFetch::Output::TT - save data via the Perl Template Toolkit |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright (c) 1998-2009 Ian Kluft. This program is free software; you can |
5
|
|
|
|
|
|
|
# redistribute it and/or modify it under the terms of the GNU General Public |
6
|
|
|
|
|
|
|
# License Version 3. See http://www.webfetch.org/GPLv3.txt |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package WebFetch::Output::TT; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1400
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
11
|
1
|
|
|
1
|
|
5
|
use base "WebFetch"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
84
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Carp; |
14
|
|
|
|
|
|
|
use Template; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# define exceptions/errors |
17
|
|
|
|
|
|
|
use Exception::Class ( |
18
|
|
|
|
|
|
|
"WebFetch::Output::TT::Exception::Template" => { |
19
|
|
|
|
|
|
|
isa => "WebFetch::TracedException", |
20
|
|
|
|
|
|
|
alias => "throw_template", |
21
|
|
|
|
|
|
|
description => "error during template processing", |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
WebFetch::Output::TT - save data via the Perl Template Toolkit |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# set defaults |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our @Options = ( "template=s", "tt_include:s" ); |
35
|
|
|
|
|
|
|
our $Usage = "--template template-file [--tt_include include-path]"; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# no user-servicable parts beyond this point |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# register capabilities with WebFetch |
40
|
|
|
|
|
|
|
__PACKAGE__->module_register( "cmdline", "output:tt" ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
In perl scripts: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
C |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
From the command line: |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
C
|
51
|
|
|
|
|
|
|
[...WebFetch input options...] --dir directory |
52
|
|
|
|
|
|
|
--dest_format tt --dest dest-path --template tt-file > |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This module saves output via the Perl Template Toolkit. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item $obj->fmt_handler_tt( $filename ) |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This function formats the data according to the Perl Template Toolkit |
61
|
|
|
|
|
|
|
template provided in the --template parameter. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Perl Template Toolkit format handler |
66
|
|
|
|
|
|
|
sub fmt_handler_tt |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
my $filename = shift; |
70
|
|
|
|
|
|
|
my $output; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# configure and create template object |
73
|
|
|
|
|
|
|
my %tt_config = ( |
74
|
|
|
|
|
|
|
ABSOLUTE => 1, |
75
|
|
|
|
|
|
|
RELATIVE => 1, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
if ( exists $self->{tt_include}) { |
78
|
|
|
|
|
|
|
$tt_config{INCLUDE_PATH} = $self->{tt_include} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
my $template = Template->new( \%tt_config ); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# process template |
83
|
|
|
|
|
|
|
$template->process( $self->{template}, { data => $self->{data}}, |
84
|
|
|
|
|
|
|
\$output, { binmode => ':utf8'} ) |
85
|
|
|
|
|
|
|
or throw_template $template->error(); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$self->raw_savable( $filename, $output ); |
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |