Mercurial > pub > Impl
annotate Lib/IMPL/Web/QueryHandler/UrlController.pm @ 191:78a18a2b6266
IMPL::Web::View improvements (unstable)
| author | cin |
|---|---|
| date | Thu, 05 Apr 2012 17:51:51 +0400 |
| parents | d1676be8afcc |
| children | 4d0e1962161c |
| rev | line source |
|---|---|
| 110 | 1 package IMPL::Web::QueryHandler::UrlController; |
| 97 | 2 use strict; |
| 166 | 3 use parent qw(IMPL::Web::QueryHandler); |
| 97 | 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 | |
| 180 | 56 C<IMPL::Web::QueryHandler::UrlController> - вызов метода на основе C<url> запроса. |
| 110 | 57 |
| 58 =head1 DESCRIPTION | |
| 59 | |
| 180 | 60 Использует переменную C<$ENV{PATH_INFO}> для получения имени и метода модуля. |
| 61 Например запрос C<http://localhost/User/register.html> интерпретируется как вызов метода C<register> | |
| 62 у модуля C<User>. | |
| 160 | 63 |
| 64 =head1 MEMBERS | |
| 65 | |
| 66 =head2 PROPERTIES | |
| 67 | |
| 68 =over | |
| 69 | |
| 70 =item C<[get,set] namespace> | |
| 71 | |
| 180 | 72 Пространство имен в котором находится модуль. по умолчению совпадает с именем класса приложения, например C<My::App> |
| 160 | 73 |
| 74 =back | |
| 110 | 75 |
| 180 | 76 =cut |
