Mercurial > pub > Impl
annotate Lib/IMPL/Web/QueryHandler/UrlController.pm @ 162:39c8788eded5
corrected PATH_INFO handling
author | wizard |
---|---|
date | Wed, 29 Dec 2010 16:55:24 +0300 |
parents | 3f09584bf189 |
children | 4267a2ac3d46 |
rev | line source |
---|---|
110 | 1 package IMPL::Web::QueryHandler::UrlController; |
97 | 2 use strict; |
3 use base qw(IMPL::Web::QueryHandler); | |
4 | |
5 use IMPL::Class::Property; | |
6 use IMPL::Exception; | |
139 | 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 | 9 |
10 BEGIN { | |
11 public property namespace => prop_all; | |
12 } | |
13 | |
14 __PACKAGE__->PassThroughArgs; | |
15 | |
16 sub Process { | |
17 my ($this,$action,$nextHandler) = @_; | |
18 | |
160 | 19 my $namespace = $this->namespace || $action->application->typeof; |
97 | 20 |
21 my @target = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("No target specified"); | |
22 | |
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 | 31 |
32 my $module = join '::',$namespace,@target; | |
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 | 36 eval "require $module; 1;" unless eval{ $module->can('InvokeAction'); }; |
37 if (my $err = $@ ) { | |
38 die new IMPL::Exception("Failed to load module",$module,$err); | |
39 } | |
97 | 40 |
41 if(UNIVERSAL::can($module,'InvokeAction')) { | |
42 $module->InvokeAction($method,$action); | |
43 } else { | |
44 die new IMPL::InvalidOperationException("Failed to invoke action",$ENV{PATH_INFO},$module,$method); | |
45 } | |
46 } | |
47 | |
110 | 48 1; |
49 | |
50 __END__ | |
51 | |
52 =pod | |
53 | |
54 =head1 NAME | |
55 | |
160 | 56 C<IMPL::Web::QueryHandler::UrlController> - вызов метода на основе C<url> запроса. |
110 | 57 |
58 =head1 DESCRIPTION | |
59 | |
60 Использует переменную C<$ENV{PATH_INFO}> для получения имени и метода модуля. | |
160 | 61 Например запрос C<http://localhost/User/register.html> интерпретируется как вызов метода C<register> |
62 у модуля C<User>. | |
63 | |
64 =head1 MEMBERS | |
65 | |
66 =head2 PROPERTIES | |
67 | |
68 =over | |
69 | |
70 =item C<[get,set] namespace> | |
71 | |
72 Пространство имен в котором находится модуль. по умолчению совпадает с именем класса приложения, например C<My::App> | |
73 | |
74 =back | |
110 | 75 |
76 =cut |