Mercurial > pub > Impl
annotate Lib/IMPL/Web/QueryHandler/UrlController.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | d1676be8afcc |
children |
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 { | |
194 | 11 public property namespace => prop_all; |
97 | 12 } |
13 | |
14 __PACKAGE__->PassThroughArgs; | |
15 | |
16 sub Process { | |
194 | 17 my ($this,$action,$nextHandler) = @_; |
18 | |
19 my $namespace = $this->namespace || $action->application->typeof; | |
20 | |
21 my @target = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("No target specified"); | |
22 | |
23 my $method = pop @target; | |
24 if ( $method =~ /^(\w+)/ ) { | |
25 $method = $1; | |
26 } else { | |
27 die new IMPL::Exception("Invalid method name",$method); | |
28 } | |
29 | |
30 (/^(\w+)$/ or die new IMPL::Exception("Invalid module name part", $_)) and $_=$1 foreach @target; | |
31 | |
32 my $module = join '::',$namespace,@target; | |
33 | |
34 die new IMPL::Exception("A module name is untrusted", $module) if tainted($module); | |
35 | |
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 } | |
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 } | |
97 | 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 |