annotate Lib/IMPL/Web/QueryHandler/UrlController.pm @ 213:d6e2ea24af08

sync
author sergey
date Fri, 03 Aug 2012 01:15:15 +0400
parents 4d0e1962161c
children
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
11 public property namespace => prop_all;
97
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 {
194
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
17 my ($this,$action,$nextHandler) = @_;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
18
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
19 my $namespace = $this->namespace || $action->application->typeof;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
20
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
21 my @target = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("No target specified");
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
22
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
23 my $method = pop @target;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
24 if ( $method =~ /^(\w+)/ ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
25 $method = $1;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
26 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
27 die new IMPL::Exception("Invalid method name",$method);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
28 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
29
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
30 (/^(\w+)$/ or die new IMPL::Exception("Invalid module name part", $_)) and $_=$1 foreach @target;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
31
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
32 my $module = join '::',$namespace,@target;
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
33
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
34 die new IMPL::Exception("A module name is untrusted", $module) if tainted($module);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
35
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
36 eval "require $module; 1;" unless eval{ $module->can('InvokeAction'); };
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
37 if (my $err = $@ ) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
38 die new IMPL::Exception("Failed to load module",$module,$err);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
39 }
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
40
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
41 if(UNIVERSAL::can($module,'InvokeAction')) {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
42 $module->InvokeAction($method,$action);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
43 } else {
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
44 die new IMPL::InvalidOperationException("Failed to invoke action",$ENV{PATH_INFO},$module,$method);
4d0e1962161c Replaced tabs with spaces
cin
parents: 180
diff changeset
45 }
97
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