annotate Lib/IMPL/Web/QueryHandler/UrlController.pm @ 157:c7652cf29a80

Fixed PostToDom with empty fields issue. Fixed the includes search order for TT::Document.
author wizard
date Wed, 20 Oct 2010 18:02:47 +0400
parents e6447ad85cb4
children 3f09584bf189
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;
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
3 use base qw(IMPL::Web::QueryHandler);
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
964587c5183c Added SecureCall to Web QueryHandlers stack
wizard
parents:
diff changeset
19 my $namespace = $this->namespace || $action->application->type;
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
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
56 C<IMPL::Web::QueryHandler::UrlController> - вызов метода на основе <url> запроса.
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
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
60 Использует переменную C<$ENV{PATH_INFO}> для получения имени и метода модуля.
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
61
c13a215508ca Refactoring,
wizard
parents: 97
diff changeset
62 =cut