annotate Lib/Engine/Output/Template.pm @ 23:716b287d4795

merge
author Sergey
date Wed, 30 Sep 2009 17:43:52 +0400
parents 03e58a454b20
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package Engine;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 our $Encoding;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4 package Engine::Output::Template;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6 use Common;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
7 use Template;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 our @ISA = qw(Object);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 our %Formats;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11 BEGIN {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
12 DeclareProperty Include => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
13 DeclareProperty ContentType => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 DeclareProperty Encoding => ACCESS_READ;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
17 sub CTOR {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18 my ($this,%args) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
19
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
20 $this->{$Include} = $args{Include} or die new Exception('An include diretory is required',$args{Format});
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
21 $this->{$ContentType} = $args{ContentType} or die new Exception('A content type must be specied',$args{Format});
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 $this->{$Encoding} = $args{Encoding};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25 sub Print {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26 my ($this,$Query,$Action) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
28 my $template = new Template(
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 INCLUDE_PATH => $this->{$Include},
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31 INTERPOLATE => 1,
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 RECURSION => 1,
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 ENCODING => $this->{$Encoding}
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
34 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 );
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 my @path = $Action->RequestURI->path_segments;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 shift @path;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
39 my $Template;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
40 eval {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
41 $Template = $template->context->template(join('/',@path));
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
42 };
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
43 print $Query->header(-type => 'text/html') and die new Exception('Failed to process a template', $@) if $@;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
44 $Query->Expires($Template->Expires);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
45 print $Query->header(-type => $this->{$ContentType});
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
46 print $template->context->process($Template,{Encoding => $Engine::Encoding, Data => $Action->Result, Query => $Query });
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
47 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
48
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
49 sub construct {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
50 my ($class,$format) = @_;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52 $class->new(%{$Formats{$format}},Format => $format);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
55 1;