49
|
1 package Engine;
|
|
2 our $Encoding;
|
|
3
|
|
4 package Engine::Output::Template;
|
|
5 use strict;
|
|
6 use Common;
|
|
7 use Template;
|
|
8 our @ISA = qw(Object);
|
|
9 our %Formats;
|
|
10
|
|
11 BEGIN {
|
|
12 DeclareProperty Include => ACCESS_READ;
|
|
13 DeclareProperty ContentType => ACCESS_READ;
|
|
14 DeclareProperty Encoding => ACCESS_READ;
|
|
15 }
|
|
16
|
|
17 sub CTOR {
|
|
18 my ($this,%args) = @_;
|
|
19
|
|
20 $this->{$Include} = $args{Include} or die new Exception('An include diretory is required',$args{Format});
|
|
21 $this->{$ContentType} = $args{ContentType} or die new Exception('A content type must be specied',$args{Format});
|
|
22 $this->{$Encoding} = $args{Encoding};
|
|
23 }
|
|
24
|
|
25 sub Print {
|
|
26 my ($this,$Query,$Action) = @_;
|
|
27
|
|
28 my $template = new Template(
|
|
29 {
|
|
30 INCLUDE_PATH => $this->{$Include},
|
|
31 INTERPOLATE => 1,
|
|
32 RECURSION => 1,
|
|
33 ENCODING => $this->{$Encoding}
|
|
34 }
|
|
35 );
|
|
36
|
|
37 my @path = $Action->RequestURI->path_segments;
|
|
38 shift @path;
|
|
39 my $Template;
|
|
40 eval {
|
|
41 $Template = $template->context->template(join('/',@path));
|
|
42 };
|
|
43 print $Query->header(-type => 'text/html') and die new Exception('Failed to process a template', $@) if $@;
|
|
44 $Query->Expires($Template->Expires);
|
|
45 print $Query->header(-type => $this->{$ContentType});
|
|
46 print $template->context->process($Template,{Encoding => $Engine::Encoding, Data => $Action->Result, Query => $Query });
|
|
47 }
|
|
48
|
|
49 sub construct {
|
|
50 my ($class,$format) = @_;
|
|
51
|
|
52 $class->new(%{$Formats{$format}},Format => $format);
|
|
53 }
|
|
54
|
|
55 1;
|