annotate Lib/IMPL/Web/TDocument.pm @ 23:716b287d4795

merge
author Sergey
date Wed, 30 Sep 2009 17:43:52 +0400
parents 94d47b388442
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
1 package IMPL::Web::TDocument;
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
2 use strict;
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
3 use warnings;
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
4
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
5 use base qw(IMPL::DOM::Node IMPL::Object::Disposable);
6
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
6 use Template::Context;
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
7 use Template::Provider;
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
9 use File::Spec;
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
10
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
11 BEGIN {
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
12 private property _Provider => prop_all;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
13 private property _Context => prop_all;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
14 public property Template => prop_get | owner_set;
6
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
15 }
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
16
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
17 our %CTOR = (
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
18 'IMPL::DOM::Node' => sub { nodeName => 'document' }
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
19 );
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
20
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
21 sub Provider {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
22 my ($this,%args) = @_;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
23
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
24 if (my $provider = $this->_Provider) {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
25 return $provider;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
26 } else {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
27 return $this->_Provider(new Template::Provider(
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
28 \%args
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
29 ));
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
30 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
31 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
32
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
33 sub Context {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
34 my ($this) = @_;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
35
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
36 if (my $ctx = $this->_Context) {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
37 return $ctx;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
38 } else {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
39 return $this->_Context (
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
40 new Template::Context(
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
41 VARIABLES => {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
42 document => $this
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
43 },
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
44 TRIM => 1,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
45 RECURSION => 1,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
46 LOAD_TEMPLATES => [$this->Provider]
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
47 )
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
48 )
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
49 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
50 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
51
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
52 sub loadFile {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
53 my ($this,$filePath,$encoding) = @_;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
54
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
55 die new IMPL::InvalidArgumentException("A filePath parameter is required") unless $filePath;
6
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
56
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
57 $encoding ||= 'utf8';
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
58
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
59 $this->_Context(undef);
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
60 $this->_Provider(undef);
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
61
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
62 my ($vol,$dir,$fileName) = File::Spec->splitpath($filePath);
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
63
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
64 my $inc = File::Spec->catpath($vol,$dir,'');
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
65
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
66 $this->Provider(
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
67 ENCODING => $encoding,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
68 INTERPOLATE => 1,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
69 PRE_CHOMP => 1,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
70 POST_CHOMP => 1,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
71 INCLUDE_PATH => $inc
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
72 );
6
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
73
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
74 $this->Template($this->Context->template($fileName));
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
75 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
76
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
77 sub Title {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
78 $_[0]->Template->Title;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
79 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
80
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
81 sub Render {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
82 my ($this) = @_;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
83
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
84 return $this->Template->process($this->Context);
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
85 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
86
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
87 sub Dispose {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
88 my ($this) = @_;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
89
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
90 $this->Template(undef);
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
91 $this->_Context(undef);
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
92 $this->_Provider(undef);
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
93
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
94 $this->SUPER::Dispose();
6
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
95 }
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
96
e2cd73ccc5bd DOM In development
Sergey
parents:
diff changeset
97 1;
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
98 __END__
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
99 =pod
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
100
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
101 =head1 SYNOPSIS
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
102
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
103 // create new document
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
104 my $doc = new IMPL::Web::TDocument;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
105
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
106 // load template
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
107 $doc->loadFile('Templates/index.tt');
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
108
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
109 // render file
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
110 print $doc->Render();
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
111
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
112 =head1 DESCRIPTION
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
113
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
114 , Template::Toolkit. ,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
115 . C<IMPL::DOM::Node>,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
116 .. DOM .
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
117
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
118 C<document> .
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
119 ,
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
120 C<Dispose> .
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
121
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
122 =head1 METHODS
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
123
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
124 =level 4
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
125
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
126 =item C<new()>
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
127
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
128
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
129
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
130 =item C<$doc->loadFile($fileName,$encoding)>
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
131
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
132 C<$fileName>, C<$encoding>.
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
133 , utf-8.
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
134
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
135 =item C<$doc->Render()>
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
136
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
137 .
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
138
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
139 =item C<$doc->Dispose()>
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
140
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
141 .
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
142
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
143 =back
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
144
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
145 =cut