comparison Lib/IMPL/Web/QueryHandler/UrlController.pm @ 110:c13a215508ca

Refactoring, ControllerUnit
author wizard
date Mon, 17 May 2010 17:42:27 +0400
parents Lib/IMPL/Web/QueryHandler/SecureCall.pm@964587c5183c
children 5a9f64890c31
comparison
equal deleted inserted replaced
109:ddf0f037d460 110:c13a215508ca
1 package IMPL::Web::QueryHandler::UrlController;
2 use strict;
3 use base qw(IMPL::Web::QueryHandler);
4
5 use IMPL::Class::Property;
6 use IMPL::Exception;
7 use Carp;
8
9 BEGIN {
10 public property namespace => prop_all;
11 }
12
13 __PACKAGE__->PassThroughArgs;
14
15 sub Process {
16 my ($this,$action,$nextHandler) = @_;
17
18 my $namespace = $this->namespace || $action->application->type;
19
20 my @target = grep $_, split /\//, ($ENV{PATH_INFO} || '') or die new IMPL::Exception("No target specified");
21
22 my $method = pop @target;
23 $method =~ s/\.\w+$//;
24
25 my $module = join '::',$namespace,@target;
26
27 eval "require $module; 1;" unless $INC{$module};
28 carp $@ if $@;
29
30 if(UNIVERSAL::can($module,'InvokeAction')) {
31 $module->InvokeAction($method,$action);
32 } else {
33 die new IMPL::InvalidOperationException("Failed to invoke action",$ENV{PATH_INFO},$module,$method);
34 }
35 }
36
37 1;
38
39 __END__
40
41 =pod
42
43 =head1 NAME
44
45 C<IMPL::Web::QueryHandler::UrlController> - вызов метода на основе <url> запроса.
46
47 =head1 DESCRIPTION
48
49 Использует переменную C<$ENV{PATH_INFO}> для получения имени и метода модуля.
50
51 =cut