annotate Lib/IMPL/Web/QueryHandler/UrlController.pm @ 180:d1676be8afcc

Перекодировка в utf-8
author sourcer
date Fri, 30 Dec 2011 23:40:00 +0300
parents 4267a2ac3d46
children 4d0e1962161c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
110
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
1 package IMPL::Web::QueryHandler::UrlController;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
2 use strict;
166
4267a2ac3d46 Added Class::Template,
wizard
parents: 160
diff changeset
3 use parent qw(IMPL::Web::QueryHandler);
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
4
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
5 use IMPL::Class::Property;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
6 use IMPL::Exception;
139
5a9f64890c31 Fixed module loading by the UriController
wizard
parents: 110
diff changeset
7 use Carp qw(croak);
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
8 use Scalar::Util qw(tainted);
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
9
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
10 BEGIN {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
11 public property namespace => prop_all;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
12 }
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
13
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
14 __PACKAGE__->PassThroughArgs;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
15
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
16 sub Process {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
17 my ($this,$action,$nextHandler) = @_;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
18
160
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
19 my $namespace = $this->namespace || $action->application->typeof;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
20
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
21 my @target = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("No target specified");
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
22
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
23 my $method = pop @target;
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
24 if ( $method =~ /^(\w+)/ ) {
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
25 $method = $1;
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
26 } else {
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
27 die new IMPL::Exception("Invalid method name",$method);
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
28 }
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
29
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
30 (/^(\w+)$/ or die new IMPL::Exception("Invalid module name part", $_)) and $_=$1 foreach @target;
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
31
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
32 my $module = join '::',$namespace,@target;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
33
148
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
34 die new IMPL::Exception("A module name is untrusted", $module) if tainted($module);
e6447ad85cb4 DOM objects now have a schema and schemaSource properties
wizard
parents: 139
diff changeset
35
139
5a9f64890c31 Fixed module loading by the UriController
wizard
parents: 110
diff changeset
36 eval "require $module; 1;" unless eval{ $module->can('InvokeAction'); };
5a9f64890c31 Fixed module loading by the UriController
wizard
parents: 110
diff changeset
37 if (my $err = $@ ) {
5a9f64890c31 Fixed module loading by the UriController
wizard
parents: 110
diff changeset
38 die new IMPL::Exception("Failed to load module",$module,$err);
5a9f64890c31 Fixed module loading by the UriController
wizard
parents: 110
diff changeset
39 }
97
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
40
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
41 if(UNIVERSAL::can($module,'InvokeAction')) {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
42 $module->InvokeAction($method,$action);
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
43 } else {
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
44 die new IMPL::InvalidOperationException("Failed to invoke action",$ENV{PATH_INFO},$module,$method);
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
45 }
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
46 }
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
47
110
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
48 1;
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
49
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
50 __END__
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
51
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
52 =pod
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
53
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
54 =head1 NAME
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
55
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
56 C<IMPL::Web::QueryHandler::UrlController> - вызов метода на основе C<url> запроса.
110
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
57
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
58 =head1 DESCRIPTION
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
59
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
60 Использует переменную C<$ENV{PATH_INFO}> для получения имени и метода модуля.
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
61 Например запрос C<http://localhost/User/register.html> интерпретируется как вызов метода C<register>
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
62 у модуля C<User>.
160
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
63
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
64 =head1 MEMBERS
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
65
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
66 =head2 PROPERTIES
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
67
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
68 =over
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
69
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
70 =item C<[get,set] namespace>
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
71
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
72 Пространство имен в котором находится модуль. по умолчению совпадает с именем класса приложения, например C<My::App>
160
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
73
3f09584bf189 Corrected web application modules
wizard
parents: 148
diff changeset
74 =back
110
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
75
180
d1676be8afcc Перекодировка в utf-8
sourcer
parents: 166
diff changeset
76 =cut