line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Any::Template::Backend; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
302
|
|
6
|
|
|
|
|
|
|
$VERSION = sprintf"%d.%03d", q$Revision: 1.8 $ =~ /: (\d+)\.(\d+)/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub process_to_file { |
9
|
0
|
|
|
0
|
1
|
|
my ($self, $data, $filepath) = @_; |
10
|
0
|
|
|
|
|
|
local *FH; |
11
|
0
|
0
|
|
|
|
|
open (FH, ">$filepath") or die("Unable to open $filepath - $!"); |
12
|
0
|
|
|
|
|
|
$self->process_to_filehandle($data, \*FH); |
13
|
0
|
|
|
|
|
|
close FH; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub process_to_filehandle { |
17
|
0
|
|
|
0
|
1
|
|
my ($self, $data, $fh) = @_; |
18
|
0
|
|
|
|
|
|
my $buffer; |
19
|
0
|
|
|
|
|
|
$self->process_to_string($data, \$buffer); |
20
|
0
|
|
|
|
|
|
print $fh $buffer; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub process_to_sub { |
24
|
0
|
|
|
0
|
1
|
|
my ($self, $data, $coderef) = @_; |
25
|
0
|
|
|
|
|
|
my $buffer; |
26
|
0
|
|
|
|
|
|
$self->process_to_string($data, \$buffer); |
27
|
0
|
|
|
|
|
|
return $coderef->($buffer); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub preprocess { |
31
|
0
|
|
|
0
|
1
|
|
return $_[1]; #no-op by default |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Any::Template::Backend - base class for implementing backends for Any::Template |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 SYNOPSIS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
package Any::Template::Backend::MyTemplate; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use MyTemplate; |
45
|
|
|
|
|
|
|
use Any::Template::Backend; |
46
|
|
|
|
|
|
|
use vars qw(@ISA); |
47
|
|
|
|
|
|
|
@ISA = qw(Any::Template::Backend); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
|
|
|
|
|
|
... |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 DESCRIPTION |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
This exists purely to be inherited from. It provides some default implementations of sending output to |
56
|
|
|
|
|
|
|
different sinks based on the lowest common denominator of returning data to a string or filehandle. |
57
|
|
|
|
|
|
|
You can override these implementations with more efficient ones where the templating engine provides them |
58
|
|
|
|
|
|
|
natively. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 API FOR BACKEND MODULES |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over 4 |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item $o = new Any::Template::Backend::MyBackend(\%options); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
You MUST supply a constructor. There is no default contructor to inherit. |
67
|
|
|
|
|
|
|
The constructor will need to marshal the options and create the backend template object from them. |
68
|
|
|
|
|
|
|
Example implementations can be found in backend classes included with the distribution. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item $templating_engine = $o->native_object() |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns the underlying native template object. You SHOULD supply this method. |
73
|
|
|
|
|
|
|
Although accessing the underlying object defeats the point of Any::Template, |
74
|
|
|
|
|
|
|
a valid use is in refactoring code, where dependencies on a particular engine's API |
75
|
|
|
|
|
|
|
can be eradicated in iterations. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item $data = $o->preprocess($data) |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
You CAN supply a method to preprocess the data structure before it's handed off to one of the process methods listed below. |
80
|
|
|
|
|
|
|
Typically you might use this to remove some values from the data structure (e.g. globrefs) that a template backend |
81
|
|
|
|
|
|
|
might not be able to handle. |
82
|
|
|
|
|
|
|
The default implementation returns $data unmodified. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item $o->process_to_string($data, $scalar_ref) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
You MUST supply this method. |
87
|
|
|
|
|
|
|
Example implementations can be found in backend classes included with the distribution. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item $o->process_to_filehandle($data, $fh) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
You CAN supply this method. If you don't, output will be collected in a string and sent to the filehandle. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item $o->process_to_sub($data, \&code) |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
You CAN supply this method. If you don't, output will be collected in a string and sent to the sub. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item $o->process_to_file($data, $filename) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
You CAN supply this method. If you don't, a filehandle will be opened against this file, |
100
|
|
|
|
|
|
|
and process_to_filehandle will be used to populate it. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 VERSION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$Revision: 1.8 $ on $Date: 2005/05/08 18:25:16 $ by $Author: johna $ |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
John Alden |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
(c) BBC 2005. This program is free software; you can redistribute it and/or modify it under the GNU GPL. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
See the file COPYING in this distribution, or http://www.gnu.org/licenses/gpl.txt |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |