annotate Lib/IMPL/Web/QueryHandler/PageFormat.pm @ 127:0dce0470a3d8

In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction added a relativeUrl function for a usage from a templates IMPL::Web::TT::Form now fully functional
author wizard
date Fri, 11 Jun 2010 20:21:07 +0400
parents 92c850d0bdb9
children e4f15cbc3f1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
1 package IMPL::Web::QueryHandler::PageFormat;
64
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
2 use base qw(IMPL::Web::QueryHandler IMPL::Object::Autofill);
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
3
c64bd1bf727d Web application
wizard
parents:
diff changeset
4 __PACKAGE__->PassThroughArgs;
c64bd1bf727d Web application
wizard
parents:
diff changeset
5
c64bd1bf727d Web application
wizard
parents:
diff changeset
6 use IMPL::Class::Property;
77
9d24db321029 Refactoring Web::TT
wizard
parents: 65
diff changeset
7 use IMPL::Web::TT::Document;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
8 use IMPL::Security::Context;
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
9 use File::Spec;
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
10 use Error qw(:try);
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
11
64
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
12 BEGIN {
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
13 public property templatesCharset => prop_all;
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
14 public property templatesBase => prop_all;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
15 public property defaultTarget => prop_all;
116
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
16 public property pathinfoPrefix => prop_all;
64
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
17 }
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
18
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
19 sub CTOR {
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
20 my ($this) = @_;
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
21
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
22 $this->templatesCharset('utf-8') unless $this->templatesCharset;
64
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
23 }
259cd3df6e53 Doc generation
wizard
parents: 63
diff changeset
24
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
25 sub Process {
c64bd1bf727d Web application
wizard
parents:
diff changeset
26 my ($this,$action,$nextHandler) = @_;
c64bd1bf727d Web application
wizard
parents:
diff changeset
27
77
9d24db321029 Refactoring Web::TT
wizard
parents: 65
diff changeset
28 my $doc = new IMPL::Web::TT::Document();
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
29
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
30 try {
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
31
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
32 $this->templatesBase($ENV{DOCUMENT_ROOT}) unless $this->templatesBase;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
33
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
34 my $pathInfo = $ENV{PATH_INFO};
116
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
35 my $prefixRoot = "";
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
36 if (my $rx = $this->pathinfoPrefix) {
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
37 $pathInfo =~ s/($rx)//;
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
38 $prefixRoot = $1 if $1;
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
39 }
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
40 local $ENV{PATH_INFO} = $pathInfo || $this->defaultTarget;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
41
127
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
42 my @path = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("PATH_INFO is empty and no defaultTarget specified" );
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
43
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
44 my @pathContainer = @path;
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
45 pop @pathContainer;
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
46
121
92c850d0bdb9 Minor changes
wizard
parents: 116
diff changeset
47 $doc->LoadFile ( File::Spec->catfile($this->templatesBase,@path), $this->templatesCharset, $this->templatesBase );
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
48 $doc->AddVar( result => $nextHandler->() );
116
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
49 $doc->AddVar( absoluteUrl => sub { "$prefixRoot/$_[0]" } );
127
0dce0470a3d8 In the IMPL::Web::ControllerUnit added the ability to notify a form about a wrong data from a transaction
wizard
parents: 121
diff changeset
50 $doc->AddVar( relativeUrl => sub { join '/', $prefixRoot, @pathContainer,$_[0] } );
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
51 {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
52 local $@;
116
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
53 $doc->AddVar( user => IMPL::Security::Context->current->principal );
1722ca51537c minor changes.
wizard
parents: 107
diff changeset
54 $doc->AddVar( session => IMPL::Security::Context->current );
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
55 warn $@ if $@;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents: 77
diff changeset
56 }
63
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
57
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
58 $action->response->contentType('text/html');
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
59 my $hOut = $action->response->streamBody;
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
60 print $hOut $doc->Render();
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
61 } finally {
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
62 $doc->Dispose;
76b878ad6596 Added serialization support for the IMPL::Object::List
wizard
parents: 62
diff changeset
63 };
62
c64bd1bf727d Web application
wizard
parents:
diff changeset
64 }
c64bd1bf727d Web application
wizard
parents:
diff changeset
65
65
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
66 1;
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
67
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
68 __END__
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
69
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
70 =pod
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
71
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
72 =head1 NAME
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
73
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
74 C<IMPL::Web::QueryHandler::PageFormat> - Выдача результатов в виде HTML страницы, построенной из шаблона.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
75
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
76 =head1 SYNOPSIS
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
77
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
78 В файле конфигурации приложения
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
79
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
80 =begin code xml
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
81
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
82 <handlersQuery type="IMPL::Object::List">
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
83 <item type="IMPL::Web::QueryHandler::PageFormat">
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
84 <charsetTemplates>utf-8</charsetTemplates>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
85 </item>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
86 </handlersQuery>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
87
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
88 =end code xml
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
89
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
90 Программно
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
91
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
92 =begin code
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
93
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
94 my $app = new IMPL::Web::Application();
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
95 $app->handlersQuery->Add(
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
96 new IMPL::Web::QueryHandler::PageFormat( charsetTemplates=> 'utf-8' );
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
97 );
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
98
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
99 =end
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
100
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
101 =head1 DESCRIPTION
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
102
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
103 Обработчик запроса для веб приложения. Загружает шаблон, путь к котрому берется
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
104 из C<ENV{PATH_INFO}> относительно пути из свойства C<templatesBase>.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
105
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
106 Наследуется от C<IMPL::Web::QueryHandler> для реализации функционала
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
107 обработчика запроса и переопределяет метод C<Process>.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
108
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
109 C<Serializable>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
110
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
111 =head1 MEMBERS
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
112
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
113 =over
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
114
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
115 =item C<CTOR(%props)>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
116
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
117 Создает новый экземпляр и заполняет свойства.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
118
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
119 =item C<[get,set] templatesCharset>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
120
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
121 Кодировка шаблонов. По умолчанию utf-8.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
122
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
123 =item C<[get,set] templatesBase>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
124
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
125 Каталог относительно которого ищется шаблон.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
126
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
127 =item C<[override] Process($action,$nextHandler)>
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
128
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
129 Метод, переопределяющий C<IMPL::Web::QueryHandler->Process> и которому передается управление
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
130 для выполнения действий.
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
131
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
132 =back
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
133
2840c4c85db8 Application configuration improvements
wizard
parents: 64
diff changeset
134 =cut